fix: synchronize automation termination and stabilize headless tests
Test / Build occurred while executing withChecks step.
Intrepid/Prometeu/Studio/pipeline/pr-master There was a failure building this commit

This commit is contained in:
2026-09-29 16:14:21 +01:00
parent 546c6d1ee5
commit 73aaeb0832
6 changed files with 105 additions and 11 deletions
@@ -9,8 +9,14 @@ import java.util.*;
/** Deliberately adversarial child process. Never packaged into production. */
public final class HeadlessFixture {
static final ObjectMapper MAPPER = new ObjectMapper();
// Allow normal JVM startup under load; call/cancel deadlines remain deliberately short.
static final HeadlessLimits LIMITS = new HeadlessLimits(600, 4096, 4096, 5000, 500, 150);
// Successful JVM/ImageIO startup and fragmented IO need headroom on CI. Only
// fixtures that deliberately hang use short call or shutdown deadlines.
static HeadlessLimits limits(String mode) {
boolean hungCall = mode.equals("hang-call") || mode.equals("hang-cancel");
boolean hungShutdown = hungCall || mode.equals("descendant");
return new HeadlessLimits(600, 4096, 4096, 5000,
hungCall ? 500 : 5000, hungShutdown ? 150 : 2000);
}
static String mode;
static void emit(JsonNode value) throws Exception {
byte[] bytes = (value.toString() + "\r\n").getBytes(java.nio.charset.StandardCharsets.UTF_8);
@@ -30,7 +36,7 @@ public final class HeadlessFixture {
var hello = MAPPER.createObjectNode().put("type", "hello").put("sessionId", "fixture").put("runtimeVersion", "fixture-only");
hello.putObject("protocolVersion").put("major", mode.equals("major") ? 2 : 1).put("minor", 3);
hello.set("capabilities", MAPPER.valueToTree(mode.equals("capabilities") ? Set.of("boot") : HeadlessWire.CAPABILITIES));
hello.set("limits", MAPPER.valueToTree(LIMITS));
hello.set("limits", MAPPER.valueToTree(limits(mode)));
if (mode.equals("limits")) ((com.fasterxml.jackson.databind.node.ObjectNode) hello.path("limits")).put("maxFrames", 900);
emit(hello);
if (mode.equals("descendant")) {
@@ -12,11 +12,10 @@ import static org.junit.jupiter.api.Assertions.*;
class HeadlessProcessSessionTest {
@TempDir Path root;
static final HeadlessLimits LIMITS = HeadlessFixture.LIMITS;
final List<HeadlessProcessSession> sessions = new ArrayList<>();
HeadlessProcessSession start(String mode) throws Exception {
var process = new ProcessBuilder(HeadlessFixture.java(), "-cp", System.getProperty("java.class.path"), HeadlessFixture.class.getName(), mode).directory(root.toFile()).start();
var session = new HeadlessProcessSession(process, new ObjectMapper(), LIMITS, "build"); sessions.add(session); return session;
var session = new HeadlessProcessSession(process, new ObjectMapper(), HeadlessFixture.limits(mode), "build"); sessions.add(session); return session;
}
@AfterEach void cleanup() { sessions.forEach(session -> session.abort("test cleanup")); }
@Test void fragmentedProtocolPreservesUnsignedFrameIdentityLayoutAndSeparateStderr() throws Exception {
@@ -58,11 +57,11 @@ class HeadlessProcessSessionTest {
var entered = new CountDownLatch(1);
try (var workers = Executors.newSingleThreadExecutor()) {
var result = workers.submit(() -> session.advance(30, ignored -> entered.countDown()));
assertTrue(entered.await(2, TimeUnit.SECONDS));
assertTrue(entered.await(5, TimeUnit.SECONDS));
assertEquals(AutomationFailure.Code.BUSY, assertThrows(AutomationException.class,
() -> session.call(TaskTools.HeadlessAction.STATE, Map.of())).failure().code());
session.cancel();
var outcome = result.get(2, TimeUnit.SECONDS);
var outcome = result.get(10, TimeUnit.SECONDS);
assertEquals(AutomationOutcome.Kind.CANCELLED, outcome.kind()); assertEquals(2, outcome.completedFrames()); assertNotNull(outcome.capture());
}
session.shutdown().toCompletableFuture().get(3, TimeUnit.SECONDS); assertFalse(session.alive());