Repository navigation
test: fix concurrency issue in testThrottlingBlocking - #2001
Conversation
|
java-storage downstream test issue is known. Joe is following up.
|
| } | ||
|
|
||
| @Test | ||
| @Test(timeout = 60000) |
There was a problem hiding this comment.
This breaks an infinite loop, if any. The normal execution time is around 1 second. 1 minute should be enough.
|
[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed!
|
|
[java_showcase_integration_tests] Kudos, SonarCloud Quality Gate passed!
|
|
[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed!
|








At the end of the test, it verifies that the batcher waited more than throttled time by capturing the argument of
callContext.withOption(). There were two problems:"Zero interactions with this mock" problem
The callContext.withOption method is called by
BatcherImpl.sendOutstanding()method viaBatcherImpl$PushCurrentBatchRunnablein another thread.sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/batching/BatcherImpl.java
Line 206 in 4c74107
Technically, there's no guarantee that the thread calls the withOption method within a certain timeframe, especially when we run the tests concurrently in a machine with many CPU cores (the nightly test setup). That's why we occasionally saw "Zero interactions with this mock" problem.
In my experiment (https://github.com/suztomo/gax-batcher-impl-test-reproducer/blob/main/README.md), increasing 100 ms timeout to 1000 ms just worked good to prevent false positives. The assertion is not about timing, but about BatcherImpl recording the throttled time correctly.
After fixing this problem, then I saw another problem below.
"expected to be at least: 50 but was: 48" problem
At the end of the test, it verifies that the batcher waited more than throttled time by capturing the argument of
callContext.withOption(). In ideal, usual scenarios,batcher.add(because of flowController) the thread and starts stopwatch to measure throttled time.throttledTime)flowController.release(), which wakes up the thread A.However, in rare cases, these events happens in this order:
batcher.add(because of flowController) and starts stopwatch to measure throttled time.flowController.release(), which wakes up the thread A.To prevent this rare case, BatcherImplTest needs to wait before sleeping 50 ms in thread B. In this pull request, I add a do-while loop to check the thread A (the thread of
batcher.add) is in Thread.State.WAITING state before making the sleeping of 50 ms.Fixes #1193 ☕️