Skip to content

Commit e9067bc

Browse files
committed
test(cli): expose probe timeout regression
1 parent bad73a0 commit e9067bc

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
import io.github.easy4j.codex.CodexClientConfig;
1919
import org.junit.jupiter.api.Test;
2020

21+
import java.nio.charset.StandardCharsets;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
import java.util.Arrays;
25+
import java.util.concurrent.TimeUnit;
26+
2127
import static org.junit.jupiter.api.Assertions.assertEquals;
2228
import static org.junit.jupiter.api.Assertions.assertFalse;
2329
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -158,6 +164,37 @@ void shouldReportFailureFromProbeWhenExecutableMissing() {
158164
assertFalse(executor.probe());
159165
}
160166

167+
@Test
168+
void shouldUseProbeTimeoutWithoutChangingNormalCommandTimeout() throws Exception {
169+
Path script = Files.createTempFile("slow-codex-", ".sh");
170+
Files.write(script, Arrays.asList(
171+
"#!/bin/sh",
172+
"sleep 2",
173+
"echo codex-test"
174+
), StandardCharsets.UTF_8);
175+
assertTrue(script.toFile().setExecutable(true));
176+
177+
CodexClientConfig config = configFor(script.toAbsolutePath().toString());
178+
config.setLocalProbeTimeoutSeconds(1);
179+
config.setLocalTimeoutSeconds(5);
180+
CodexCliExecutor executor = new CodexCliExecutor(config);
181+
182+
long probeStarted = System.nanoTime();
183+
assertFalse(executor.probe());
184+
long probeElapsedMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - probeStarted);
185+
assertTrue(probeElapsedMs < 3_500,
186+
"probe must use localProbeTimeoutSeconds instead of localTimeoutSeconds");
187+
188+
long executeStarted = System.nanoTime();
189+
CodexCliResult normal = executor.execute("--version");
190+
long executeElapsedMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - executeStarted);
191+
assertTrue(normal.isSuccess(), "normal command must still use localTimeoutSeconds");
192+
assertTrue(executeElapsedMs >= 1_500,
193+
"normal command should be allowed to outlive the probe timeout");
194+
195+
Files.deleteIfExists(script);
196+
}
197+
161198
@Test
162199
void shouldTimeoutOnHangingProcess() {
163200
// Use a short timeout and a command that sleeps for a long time.

0 commit comments

Comments
 (0)