benbjohnson/clock

Unit tests fail with GOMAXPROCS=8

inercia opened this issue · 5 comments

Unit tests fail when we increase the number of threads:

$ export GOMAXPROCS=8
$ go test
--- FAIL: TestMock_After-8 (0.00s)
        clock_test.go:203: too late
--- FAIL: ExampleMock_After (0.00s)
got:
1970-01-01 00:00:00 +0000 UTC: 0
1970-01-01 00:00:05 +0000 UTC: 0
1970-01-01 00:00:10 +0000 UTC: 0
want:
1970-01-01 00:00:00 +0000 UTC: 0
1970-01-01 00:00:05 +0000 UTC: 0
1970-01-01 00:00:10 +0000 UTC: 100
--- FAIL: ExampleMock_Ticker (0.00s)
got:
Count is 0 after 10 seconds
Count is 0 after 15 seconds
want:
Count is 10 after 10 seconds
Count is 15 after 15 seconds
--- FAIL: ExampleMock_Timer (0.00s)
got:
Count is 0 after 10 seconds
want:
Count is 1 after 10 seconds
FAIL
exit status 1
FAIL    github.com/benbjohnson/clock    0.304s

The tests that fail change between executions....

@inercia Can you verify the fix in #5?

@benbjohnson
For the record I ran the test like so and got (un)lucky:

[benfleis] ~/src/clock $ GOMAXPROCS=24 go test
--- FAIL: TestClock_Timer_Reset (0.02s)
        clock_test.go:210: too early
FAIL
exit status 1
FAIL    github.com/benbjohnson/clock    0.471s

I then ran it 10 more times, no failure. I'm running on a 4 cpu box, but wouldn't expect that GOMAXPROCS should ever change the behavior in this case.

Unfortunately it's not possible to control Go's scheduler so I'm not sure that I have a solution to this issue. Increasing the sleep time may solve it but that's definitely a hack.

I just landed #34 which might hav addressed this. At any rate, let's re-open if this is still an issue.