You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "ok2c (via GitHub)" <gi...@apache.org> on 2023/09/01 14:01:44 UTC
[GitHub] [httpcomponents-core] ok2c commented on a diff in pull request #426: Refactor testGetWithTimeout for Reliability
ok2c commented on code in PR #426:
URL: https://github.com/apache/httpcomponents-core/pull/426#discussion_r1313069605
##########
httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestBasicFuture.java:
##########
@@ -260,35 +260,36 @@ public void cancelled() {
@Test
void testGetWithTimeout() {
+ final AtomicBoolean isFutureCompleted = new AtomicBoolean(false);
+
final FutureCallback<String> callback = new FutureCallback<String>() {
@Override
public void completed(final String result) {
- // Nothing to do
+ isFutureCompleted.set(true);
}
@Override
public void failed(final Exception ex) {
- // Nothing to do
+ // Nothing to do here for this example
}
@Override
public void cancelled() {
- // Nothing to do
+ // Nothing to do here for this example
}
};
final BasicFuture<String> future = new BasicFuture<>(callback);
- new Thread(() -> {
- try {
- Thread.sleep(100); // This simulates the delay in completing the future.
- future.completed("test");
- } catch (final InterruptedException e) {
- future.failed(e);
- }
- }).start();
+ new Thread(() -> future.completed("test")).start();
+ // Poll until the future is completed or timeout
assertTimeoutPreemptively(Duration.ofMillis(200), () -> {
+ while (!isFutureCompleted.get()) {
Review Comment:
@arturobernalg Is busy loop the only way to reliably test this condition?
--
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: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org