|
23 | 23 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
24 | 24 | import static org.junit.jupiter.api.Assertions.assertTrue; |
25 | 25 |
|
| 26 | +import java.nio.file.Paths; |
| 27 | +import java.util.concurrent.TimeUnit; |
| 28 | + |
26 | 29 | /** |
27 | 30 | * Unit tests for {@link CodexCliExecutor}. |
28 | 31 | * |
|
36 | 39 | */ |
37 | 40 | class CodexCliExecutorTest { |
38 | 41 |
|
| 42 | + private static final String SLOW_CODEX_SCRIPT = |
| 43 | + Paths.get("src", "test", "resources", "slow-codex.sh").toAbsolutePath().toString(); |
| 44 | + |
39 | 45 | private CodexClientConfig configFor(String executable) { |
40 | 46 | CodexClientConfig config = new CodexClientConfig(); |
41 | 47 | config.setLocalExecutable(executable); |
@@ -158,14 +164,31 @@ void shouldReportFailureFromProbeWhenExecutableMissing() { |
158 | 164 | assertFalse(executor.probe()); |
159 | 165 | } |
160 | 166 |
|
| 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 | + |
161 | 183 | @Test |
162 | 184 | 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); |
165 | 188 | config.setLocalTimeoutSeconds(1); |
166 | 189 | CodexCliExecutor executor = new CodexCliExecutor(config); |
167 | 190 |
|
168 | | - CodexCliResult result = executor.execute("-c", "sleep 60"); |
| 191 | + CodexCliResult result = executor.execute(); |
169 | 192 |
|
170 | 193 | // On macOS/Linux the watchdog kills the process; the exit code is -1 |
171 | 194 | // and stderr contains the timeout notice. |
|
0 commit comments