dsmiley commented on PR #772:
URL: https://github.com/apache/solr/pull/772#issuecomment-1123190341
I'm not sure allowing 4 is in the spirit of the test's purpose. Instead, I
think the assertion should be re-attempted after some time. I tried this
locally:
```java
private void assertEventually(int upToTime, TimeUnit unit, Runnable task) {
final long startNanos = System.nanoTime();
for (int attempt = 1; true; attempt++) {
try {
task.run();
} catch (AssertionError | RuntimeException e) {
final long elapsedNanos = System.nanoTime() - startNanos;
final long remainingNanos = unit.toNanos(upToTime) - elapsedNanos;
if (remainingNanos <= 0) {
throw e;
}
try {
// sleep with exponential back-off. Don't exceed remaining time.
Not shorter than 5 ms.
final long sleepNanos = Math.min(Math.max(5000, elapsedNanos),
remainingNanos);
Thread.sleep(TimeUnit.NANOSECONDS.toMillis(sleepNanos));
} catch (InterruptedException ie) {
throw e; // throw original exception, not the interrupted one
}
System.err.println("Retry attempt " + attempt);
continue; // try again
}
return; // success!
}
}
```
And debugged it a bit to ensure it does what it's supposed to do. I think
this will work for this scenario and we could even add this utility method
somewhere if we want it elsewhere. The name is debatable; could be retryUntil.
I found `org.apache.solr.common.util.RetryUtil` which is pretty similar. Come
to think of it, maybe we should just call that existing code -- `retryUntil` ?
(I debated to create a whole new PR or push commits reverting your change,
or to just comment here so I just put here as a comment for now)
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]