-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix two flaky tests #30278
Fix two flaky tests #30278
Conversation
410b069
to
907d784
Compare
@@ -165,6 +165,7 @@ public void testCloseVisibleToAwaitCompletionCallerAndProducer() throws Exceptio | |||
Future<?> future2 = | |||
executor.submit( | |||
() -> { | |||
Thread.sleep(500); // give the previous future some time to reach the inf while loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Busy sleep is generally not preferable. Consider use wait/notify which sounds exactly what we need here? That is block this thread until future1 reaches while(true)
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
Run Java PreCommit |
Run Java PreCommit |
sdks/java/core/src/test/java/org/apache/beam/sdk/fn/data/BeamFnDataInboundObserverTest.java
Outdated
Show resolved
Hide resolved
@@ -553,7 +553,7 @@ public void testThreadsAreAddedOnlyAsNeededWithContention() throws Exception { | |||
LOG.info("Created {} threads to execute at most 100 parallel tasks", largestPool); | |||
// Ideally we would never create more than 100, however with contention it is still possible | |||
// some extra threads will be created. | |||
assertTrue(largestPool <= 104); | |||
assertTrue(largestPool <= 110); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity, you mind explain briefly about the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the comment above the change says, there could be more than 100 threads created in the UnboundedScheduledExecutorService
. The previous threshold is set to 104 but it causes some flakiness recently. I attempt to increase to a little bit more to see if it can stop or at least reduce the chance of failure.
@@ -165,6 +171,11 @@ public void testCloseVisibleToAwaitCompletionCallerAndProducer() throws Exceptio | |||
Future<?> future2 = | |||
executor.submit( | |||
() -> { | |||
synchronized (isReady) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, actually this cannot be synchronized (either using this or isReady). Because synchronized block will block other thread's same synchronized block. Here it will wait for signal indefinitely and cause deadlock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using synchronized block on isReady works here. I don't see there is a deadlock.
(1) If it runs the first synchronized block first, then it will call notify() and isReady is set to true. Then when the second synchronized block is executed, it will not reach the wait() call because isReady is true.
(2) If it runs the second synchronized block first, then it will wait() and give up the lock. Then in the first synchronized block, it will pick up the lock, set isReady to true, and then call notify().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I confused myself, LGTM
Looks like the second flaky test is still there after the fix, though the frequency seems lower. |
For test of
testCloseVisibleToAwaitCompletionCallerAndProducer
BeamFnDataInboundObserver.CloseException
thrown at callingfuture.get()
.For test
testThreadsAreAddedOnlyAsNeededWithContention
, my attempt is to increase the threshold so we can allow more extra threads being created.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123
), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.