-
Notifications
You must be signed in to change notification settings - Fork 65
test: BatcherImplTest.testThrottlingBlocking to check actual wait time #2285
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
Changes from all commits
a097345
2d728b7
3fdf1cd
2200df4
a141709
1733aac
fde5f06
abb02e5
910498a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,8 @@ | |
@RunWith(JUnit4.class) | ||
public class BatcherImplTest { | ||
|
||
private static final Logger logger = Logger.getLogger(BatcherImplTest.class.getName()); | ||
|
||
private static final ScheduledExecutorService EXECUTOR = | ||
Executors.newSingleThreadScheduledExecutor(); | ||
|
||
|
@@ -871,6 +873,7 @@ public void testThrottlingBlocking() throws Exception { | |
public void run() { | ||
batcherAddThreadHolder.add(Thread.currentThread()); | ||
batcher.add(1); | ||
logger.info("Called batcher.add(1)"); | ||
} | ||
}); | ||
|
||
|
@@ -885,20 +888,38 @@ public void run() { | |
} while (batcherAddThreadHolder.isEmpty() | ||
|| batcherAddThreadHolder.get(0).getState() != Thread.State.WAITING); | ||
|
||
long beforeGetCall = System.currentTimeMillis(); | ||
executor.submit( | ||
() -> { | ||
try { | ||
Thread.sleep(throttledTime); | ||
logger.info("Calling flowController.release"); | ||
blakeli0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
flowController.release(1, 1); | ||
logger.info("Called flowController.release"); | ||
} catch (InterruptedException e) { | ||
} | ||
}); | ||
|
||
try { | ||
logger.info("Calling future.get(10 ms)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not too familiar with Batcher or this test, but what is the significance of 10ms here? If a TimeoutException is expected, why can't we lower the future.get() block time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the log (in the pull request description), the problem is that the TimeoutException isn't always thrown. Lowering the 10 ms to smaller number won't help. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I read the original comment For my understanding, do you know what causes this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, from my understanding it would be either case:
I think that should suffice due to the variance in scheduling. CC: @blakeli0 Do you know of another option to handle this flakiness? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, I didn't observe that. What I observed in #1931 was "future.get() took more than 10ms to return normally, without TimeoutException". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, updated the comment above. The docs for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's correct. |
||
future.get(10, TimeUnit.MILLISECONDS); | ||
assertWithMessage("adding elements to batcher should be blocked by FlowControlled").fail(); | ||
long afterGetCall = System.currentTimeMillis(); | ||
long actualWaitTimeMs = afterGetCall - beforeGetCall; | ||
|
||
logger.info("future.get(10 ms) unexpectedly returned. Wait time: " + actualWaitTimeMs); | ||
// In a flaky test troubleshooting | ||
// (https://github.com/googleapis/sdk-platform-java/issues/1931), we observed that | ||
// "future.get" method did not throw TimeoutException in this multithreaded test. | ||
// It's because the thread calling "future.get" was not being run (i.e. in the wait queue of | ||
// CPUs) in a timely manner. | ||
// To avoid the flakiness, as long as the "future.get" does not return before the specified | ||
// timeout, this assertion is considered as good. | ||
assertWithMessage("adding elements to batcher should be blocked by FlowControlled") | ||
.that(actualWaitTimeMs) | ||
.isAtLeast(10); | ||
} catch (TimeoutException e) { | ||
// expected | ||
logger.info("future.get(10 ms) timed out expectedly."); | ||
} | ||
|
||
try { | ||
|
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.
I keep this just in case the problem occurs again and we have the logging. This surefire (unit test) configuration does not affect the released libraries to users.