fako1024/httpc

Race conditions in test routines

Closed this issue · 3 comments

There seem to be two (probably unrelated) race conditions in test executions:

  • In TestCertificateInstance:
2023/04/14 09:34:19 Unsolicited response received on idle HTTP channel starting with "HTTP/0.0 200 OK\r\n"; err=<nil>
    /home/fako/Develop/go/src/github.com/fako1024/httpc/tls_test.go:218: Get "https://127.0.0.1:10002/": readLoopPeekFailLocked: %!w(<nil>)
httpc_test.go:103: Get "http://127.0.0.1/uiatbucacajdahgsdkjasdgcagagd/timeout": dial tcp 127.0.0.1:80: i/o timeout

The first issue seems to be a local artifact only (happens when saving too fast and two tests run concurrently - which causes some other issues as well).
The second one seems to only occur on Windows (my guess it that there's some minor differences in timeout handling there) and needs further investigation:

I can reproduce the issue quite reliably on a Windows machine. This might be similar / related...

Digging a little deeper (to the extend possible) it seems that for some reason Windows doesn't cope very well with the (synthetically) short test timeout of one nanosecond (and sometimes fires off the timeout instead of the expired context timeout error).
If I slightly increase the timeout for the test routine, the issue stops happening. At a timeout of 25 ms I was already unable to reproduce the issue in thousands of test runs, while at 20 ms it was still happening quite frequently.
Given that it's a rather unlikely scenario to use such a short timeout I'll increase the timeout for the test on Windows to 100 ms.