Copilot commented on code in PR #387:
URL: 
https://github.com/apache/maven-shared-utils/pull/387#discussion_r3644895177


##########
src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java:
##########
@@ -20,14 +20,43 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.Duration;
 
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
 
 public class StreamPollFeederTest {
 
+    @Test
+    public void waitUntilFeederDoneWithContinuousData() {
+        // Simulates a stream with continuous data where the feeder thread
+        // never enters the synchronized(lock) wait block, so the done
+        // flag must be visible without relying on lock's happens-before.
+        InputStream continuousInput = new InputStream() {
+            @Override
+            public int available() {
+                return 1;
+            }
+
+            @Override
+            public int read() throws IOException {
+                return 0;
+            }
+        };
+
+        assertTimeoutPreemptively(Duration.ofSeconds(5), () -> {
+            StreamPollFeeder feeder = new StreamPollFeeder(continuousInput, 
new ByteArrayOutputStream());
+            feeder.start();
+            feeder.waitUntilDone();
+            assertNull(feeder.getException());

Review Comment:
   This timeout-preemptive test can still leave a runaway non-daemon 
`StreamPollFeeder` thread running if the bug ever regresses (JUnit cancels the 
lambda thread, but does not stop spawned threads). Also, using 
`ByteArrayOutputStream` here risks unbounded heap growth if the feeder keeps 
writing. Consider using a discard `OutputStream` and mark the feeder thread as 
daemon to keep the test suite from hanging/OOMing on failure.



-- 
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]

Reply via email to