thc202 commented on code in PR #426:
URL: 
https://github.com/apache/httpcomponents-core/pull/426#discussion_r1313139826


##########
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:
   Wouldn't a `CountDownLatch` work for this case?



-- 
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-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to