Skip to content

testdata: attempt to deflake timers/goroutines tests#5384

Open
jakebailey wants to merge 2 commits into
tinygo-org:devfrom
jakebailey:fix-flaky-tests
Open

testdata: attempt to deflake timers/goroutines tests#5384
jakebailey wants to merge 2 commits into
tinygo-org:devfrom
jakebailey:fix-flaky-tests

Conversation

@jakebailey
Copy link
Copy Markdown
Member

Fixes #4963
Fixes #4965

I got tired of hitting these flakes locally and in CI. These changes seem to make them pass, but it's a little unclear without more eyes whether or not I have defeated the purpose of these tests somehow as I of course arrived here after these were committed...

The timers test interleaved goroutine prints with ticker/timer waits,
which produced non-deterministic output ordering under thread-based
scheduling. On loaded systems, the goroutine prints could race with
the ticker ticks, causing test failures.

Fix by synchronizing the goroutine via a done channel before the
first tick arrives. The goroutine still runs concurrently with the
ticker (proving both mechanisms work together), but finishes well
before the tick fires so the output order is deterministic.

Also use wider timing margins (goroutine at 100/200ms vs ticker at
500ms) to avoid races on slow CI machines.

Addresses tinygo-org/tinygo issue 4963.
The goroutines test had two races under thread-based scheduling:

1. "main 2" vs "sub 2": both printed around 100-200ms from start,
   racing on loaded systems. Fixed by using channel synchronization
   between main and sub() instead of relying on sleep timing.

2. "slept inside func pointer" vs "slept inside closure": both
   goroutines launched by sleepFuncValue slept 1ms then printed,
   with only a 1ms gap between launches. Fixed by waiting for each
   goroutine to complete via a done channel before starting the next.

The test still exercises goroutine creation, function value calls,
closure captures, and channel communication.

Addresses tinygo-org/tinygo issue 4965.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

goroutines.go may be flaky timers.go may be flaky

1 participant