Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ private void launchLocked(long epoch, Map<String, String> environment, AgentConf
}
builder.redirectErrorStream(true).redirectOutput(ProcessBuilder.Redirect.appendTo(logFile.toFile()));

if (status.epoch() != epoch) return;
Process spawned = builder.start();
try (OutputStream stdin = spawned.getOutputStream()) {
stdin.write(frame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,10 @@ public void stopDuringAsyncLaunchFailureNeverRevertsStatusFromStopped() throws E
runner.stop();
assertStoppedSnapshot(runner);

assertTrue("Expected queued stop teardown notification", stopNotified.await(5, TimeUnit.SECONDS));
assertTrue("Expected stop status notification", stopNotified.await(5, TimeUnit.SECONDS));
}

// Queue a second stop and wait for its observer callback as a FIFO barrier on serial + notices.
CountDownLatch drained = new CountDownLatch(1);
CountDownLatch notified = new CountDownLatch(1);
try (AutoCloseable ignored = AlphaLocalAgentRunner.observe(() -> {
if (!runner.isActive()) {
JSONObject status = runner.statusJson();
Expand All @@ -256,11 +255,12 @@ public void stopDuringAsyncLaunchFailureNeverRevertsStatusFromStopped() throws E
if (!"stopped".equals(state) || epoch != 0L || status.has("failure") || status.has("error")) {
violation.compareAndSet(null, "Observed non-stopped snapshot while draining: " + status);
}
drained.countDown();
notified.countDown();
}
})) {
runner.stop();
assertTrue("Expected serial drain barrier", drained.await(5, TimeUnit.SECONDS));
assertTrue("Expected stop status notification", notified.await(5, TimeUnit.SECONDS));
assertStoppedAfterLaunches(runner);
}

assertEquals(null, violation.get());
Expand Down Expand Up @@ -329,7 +329,7 @@ public void repeatedStartRestartStopCyclesKeepStoppedStateAndMonotonicEpochs() t
}
}

CountDownLatch drained = new CountDownLatch(1);
CountDownLatch notified = new CountDownLatch(1);
try (AutoCloseable ignored = AlphaLocalAgentRunner.observe(() -> {
if (!runner.isActive()) {
JSONObject status = runner.statusJson();
Expand All @@ -339,17 +339,23 @@ public void repeatedStartRestartStopCyclesKeepStoppedStateAndMonotonicEpochs() t
|| status.has("error")) {
violation.compareAndSet(null, "Observed stale state after final drain: " + status);
}
drained.countDown();
notified.countDown();
}
})) {
runner.stop();
assertTrue("Expected final drain barrier", drained.await(5, TimeUnit.SECONDS));
assertTrue("Expected stop status notification", notified.await(5, TimeUnit.SECONDS));
assertStoppedAfterLaunches(runner);
}

assertEquals(null, violation.get());
assertStoppedSnapshot(runner);
}

private static void assertStoppedAfterLaunches(AlphaLocalAgentRunner runner) throws Exception {
ScheduledThreadPoolExecutor launches = ReflectionHelpers.getField(runner, "serial");
launches.submit(() -> assertStoppedSnapshot(runner)).get(5, TimeUnit.SECONDS);
}

private static void assertStoppedSnapshot(AlphaLocalAgentRunner runner) {
assertFalse(runner.isActive());
assertFalse(runner.isRunning());
Expand Down
Loading