Skip to content

Commit 389b93b

Browse files
committed
test: try to fix what looks like a race condition on linux
1 parent e58008f commit 389b93b

File tree

1 file changed

+14
-1
lines changed
  • testprocesses-core/src/test/java/io/github/netmikey/testprocesses/functional/testfixtures

1 file changed

+14
-1
lines changed

testprocesses-core/src/test/java/io/github/netmikey/testprocesses/functional/testfixtures/TestHelper.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.UncheckedIOException;
99
import java.nio.charset.StandardCharsets;
1010
import java.util.Optional;
11+
import java.util.concurrent.TimeoutException;
1112

1213
import org.junit.jupiter.api.Assertions;
1314
import org.opentest4j.AssertionFailedError;
@@ -17,13 +18,17 @@
1718
import io.github.netmikey.testprocesses.TestProcessDefinitionBy;
1819
import io.github.netmikey.testprocesses.TestProcessState;
1920
import io.github.netmikey.testprocesses.TestProcessesRegistry;
21+
import io.github.netmikey.testprocesses.eventdetector.LogPatternEventDetector;
2022

2123
/**
2224
* Utility method for asserting and interacting with those test processes
2325
* specifically created for these framework-tests.
2426
*/
2527
public class TestHelper {
2628

29+
private static final TestProcessDefinitionBy<EchoTestProcess> ECHO_TEST_PROCESS = TestProcessDefinitionBy
30+
.clazz(EchoTestProcess.class);
31+
2732
/**
2833
* Sends a line of test to the {@link EchoTestProcess} currently running in
2934
* the specified registry.
@@ -35,7 +40,7 @@ public class TestHelper {
3540
*/
3641
public static void sendToEchoProcess(TestProcessesRegistry registry, String line) {
3742
Optional<RunningTestProcess<EchoTestProcess>> runningProcess = registry
38-
.retrieveRunningProcess(TestProcessDefinitionBy.clazz(EchoTestProcess.class));
43+
.retrieveRunningProcess(ECHO_TEST_PROCESS);
3944

4045
if (runningProcess.isPresent()) {
4146
try {
@@ -56,6 +61,14 @@ public static void sendToEchoProcess(TestProcessesRegistry registry, String line
5661
} catch (IOException e) {
5762
throw new UncheckedIOException(e.getMessage(), e);
5863
}
64+
65+
// Wait for the line to appear on the echo process' stdOut
66+
try {
67+
registry.waitForEventOn(ECHO_TEST_PROCESS, LogPatternEventDetector.onStdOut().withMarker(line));
68+
} catch (TimeoutException e) {
69+
throw new RuntimeException("Timeout while waiting for the line to appear on the EchoProcess' stdOut",
70+
e);
71+
}
5972
} else {
6073
throw new IllegalStateException("Trying to write to " + EchoTestProcess.class.getName()
6174
+ "'s stdIn, but no process is running.");

0 commit comments

Comments
 (0)