8000 Fix flaky test in SemaphoreSpec by kyri-petrou · Pull Request #9492 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix flaky test in SemaphoreSpec #9492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

kyri-petrou
Copy link
Contributor

I'm actually surprised this test hasn't been flaky more often. Since the first invocation of semaphore.withPermit(promise.await) was forked, if the forking in the line below won the race then the test would never complete.

Fixed it by making all of semaphore.await on the promise, so that we can guarantee none of them wins the race and completes. Also annotated the entire suite with nonFlaky just in case

@kyri-petrou kyri-petrou requested a review from hearnadam January 23, 2025 05:36
_ <- promise.succeed(())
waitingEnd <- semaphore.awaiting.repeatUntil(_ == 0)
} yield assertTrue(waitingStart == 10, waitingEnd == 0)
} @@ timeout(10.seconds)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we lower the timeout if we lower the number of waiters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can although I'm a bit reluctant lowering timeouts too much as the CI server runs with limited CPU/threads and the tests run in parallel, so it's possible that adding another CPU-intensive test might trigger a timeout in this one if we set it too low.

Also note that 10 seconds should be the total time of the test (100 iterations due to nonFlaky)

@kyri-petrou kyri-petrou merged commit 27fb8af into zio:series/2.x Jan 23, 2025
18 checks passed
6BA6
@kyri-petrou kyri-petrou deleted the fix-flaky-semaphore-test branch January 23, 2025 08:18
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.

2 participants
0