gemini-code-assist[bot] commented on code in PR #38970:
URL: https://github.com/apache/beam/pull/38970#discussion_r3416284164
##########
sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/AsyncWrapperTest.java:
##########
@@ -230,21 +230,20 @@ private void waitForEmpty(AsyncWrapper<?, ?, ?>
asyncWrapper) {
}
private void waitForEmpty(AsyncWrapper<?, ?, ?> asyncWrapper, int
timeoutSeconds) {
- int count = 0;
+ long limit = System.currentTimeMillis() + timeoutSeconds * 1000L;
while (!asyncWrapper.isEmpty()) {
+ if (System.currentTimeMillis() > limit) {
+ throw new RuntimeException("Timed out waiting for async dofn to be
empty");
+ }
Review Comment:

Using `System.currentTimeMillis()` to measure elapsed time or timeouts is
unreliable because it is sensitive to system clock adjustments (e.g., NTP
synchronization). It is recommended to use `System.nanoTime()` for monotonic
time measurements.
```suggestion
long limit = System.nanoTime() + timeoutSeconds * 1_000_000_000L;
while (!asyncWrapper.isEmpty()) {
if (System.nanoTime() > limit) {
throw new RuntimeException("Timed out waiting for async dofn to be
empty");
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]