Skip to content

Commit d192cc9

Browse files
committed
test(cli): expose probe timeout semantics
1 parent 60f0f86 commit d192cc9

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

src/test/java/io/github/easy4j/codex/cli/CodexCliExecutorTest.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import static org.junit.jupiter.api.Assertions.assertNotNull;
2424
import static org.junit.jupiter.api.Assertions.assertTrue;
2525

26+
import java.nio.file.Paths;
27+
import java.util.concurrent.TimeUnit;
28+
2629
/**
2730
* Unit tests for {@link CodexCliExecutor}.
2831
*
@@ -36,6 +39,9 @@
3639
*/
3740
class CodexCliExecutorTest {
3841

42+
private static final String SLOW_CODEX_SCRIPT =
43+
Paths.get("src", "test", "resources", "slow-codex.sh").toAbsolutePath().toString();
44+
3945
private CodexClientConfig configFor(String executable) {
4046
CodexClientConfig config = new CodexClientConfig();
4147
config.setLocalExecutable(executable);
@@ -158,14 +164,31 @@ void shouldReportFailureFromProbeWhenExecutableMissing() {
158164
assertFalse(executor.probe());
159165
}
160166

167+
@Test
168+
void shouldUseDedicatedProbeTimeoutWithoutChangingNormalTimeout() {
169+
CodexClientConfig config = configFor("/bin/sh " + SLOW_CODEX_SCRIPT);
170+
config.setLocalProbeTimeoutSeconds(1);
171+
config.setLocalTimeoutSeconds(8);
172+
CodexCliExecutor executor = new CodexCliExecutor(config);
173+
174+
long started = System.nanoTime();
175+
boolean available = executor.probe();
176+
long elapsedMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started);
177+
178+
assertFalse(available, "probe must time out using localProbeTimeoutSeconds");
179+
assertTrue(elapsedMs < 3_000,
180+
"probe must not wait for the normal localTimeoutSeconds window; elapsed=" + elapsedMs);
181+
}
182+
161183
@Test
162184
void shouldTimeoutOnHangingProcess() {
163-
// Use a short timeout and a command that sleeps for a long time.
164-
CodexClientConfig config = configFor("/bin/sh");
185+
// Keep the blocking loop in the shell process itself so killing the
186+
// shell closes stdout/stderr immediately.
187+
CodexClientConfig config = configFor("/bin/sh " + SLOW_CODEX_SCRIPT);
165188
config.setLocalTimeoutSeconds(1);
166189
CodexCliExecutor executor = new CodexCliExecutor(config);
167190

168-
CodexCliResult result = executor.execute("-c", "sleep 60");
191+
CodexCliResult result = executor.execute();
169192

170193
// On macOS/Linux the watchdog kills the process; the exit code is -1
171194
// and stderr contains the timeout notice.

0 commit comments

Comments
 (0)