Skip to content

Commit 4c63e6c

Browse files
authored
test: deflake five single-OS CI failure classes under -T1C contention (#4556)
1 parent 593a466 commit 4c63e6c

5 files changed

Lines changed: 83 additions & 3 deletions

File tree

‎agentscope-examples/agents/agentscope-chat/src/test/java/io/agentscope/examples/chat/ChatControllerTest.java‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void httpUsesExplicitCreationAndTargetedIdempotentControls() throws Exception {
6464
new ChatSessions(
6565
workspace,
6666
new DemoChatModel(Duration.ofMillis(2), Duration.ofMillis(10)))) {
67-
var web = WebTestClient.bindToController(new ChatController(sessions)).build();
67+
var web = webClient(new ChatController(sessions));
6868
web.get().uri("/api/sessions/conversation").exchange().expectStatus().isNotFound();
6969
assertTrue(sessions.list().isEmpty());
7070
web.post().uri("/api/sessions/conversation").exchange().expectStatus().isOk();
@@ -188,7 +188,7 @@ void sseUsesReconnectHeaderAndDisconnectDoesNotCancelTask() throws Exception {
188188
assertEquals(turn, payload.path("turnId").asText());
189189
ChatSessionsTest.await(
190190
sessions, s -> ChatSessionsTest.status(s, turn) == TurnStatus.SUCCEEDED);
191-
var web = WebTestClient.bindToController(controller).build();
191+
var web = webClient(controller);
192192
web.get()
193193
.uri("/api/sessions/conversation/events?after=invalid")
194194
.accept(MediaType.APPLICATION_JSON)
@@ -221,4 +221,18 @@ void toolOutputPreviewIsDeliveredWithoutAdvancingTheSessionCursor() throws Excep
221221
assertFalse(delta.path("data").path("data").asText().isBlank());
222222
}
223223
}
224+
225+
/**
226+
* Every exchange that reaches the store borrows a SQLite connection with {@code
227+
* busy_timeout}=10s and commits its writes durably, so WebTestClient's default 5s response
228+
* timeout is below the store's own budget: #4481 (2026-11-28, windows-latest) crossed it on the
229+
* idempotent replay, 6.61s for the test against 1.45-6.00s when green on windows-latest
230+
* (0.45-2.30s on ubuntu).
231+
*/
232+
private static WebTestClient webClient(ChatController controller) {
233+
return WebTestClient.bindToController(controller)
234+
.configureClient()
235+
.responseTimeout(Duration.ofSeconds(15))
236+
.build();
237+
}
224238
}

‎agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessContextRegressionTest.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.agentscope.core.agent.test.MockModel;
2525
import io.agentscope.core.event.AgentResultEvent;
2626
import io.agentscope.core.event.ConfirmResult;
27+
import io.agentscope.core.journal.InMemoryThreadJournalStore;
2728
import io.agentscope.core.message.GenerateReason;
2829
import io.agentscope.core.message.Msg;
2930
import io.agentscope.core.message.MsgRole;
@@ -62,6 +63,18 @@
6263
import org.junit.jupiter.params.provider.CsvSource;
6364
import org.junit.jupiter.params.provider.ValueSource;
6465

66+
/**
67+
* Every HarnessAgent in this class uses an ephemeral {@link InMemoryThreadJournalStore}. The tests
68+
* assert agent behavior over the native Thread journal (compaction, background delivery, skill
69+
* loading, spawn and resume, tool visibility), not its persistence backend, and the default
70+
* workspace journal is SQLite on Windows: one connection and one durable transaction per storage
71+
* operation costs the journal-enabled rows of the two parameterized tests 0.7-4.3s there against
72+
* 0.01-0.05s for the journal-disabled rows (0.18-0.72s and 0.05-0.21s on ubuntu). Under -T1C load
73+
* journaled invocations stopped finishing within their {@code block} deadlines (Surefire elapsed up
74+
* to 15.56s) in ten windows-latest runs between 2026-11-26 and 2026-12-02 (#4102, #4470, #4499,
75+
* #4508, #4509, #4441, #4515, #4541, #4551, #4213) while the journal-disabled rows stayed at
76+
* 0.01-0.47s.
77+
*/
6578
class HarnessContextRegressionTest {
6679
@TempDir Path workspace;
6780
private final String dynamicSession = UUID.randomUUID().toString();
@@ -107,6 +120,7 @@ void ordinaryCompactionKeepsTheLatestUserMessageAfterSeveralToolSteps() {
107120
try (var agent =
108121
HarnessAgent.builder()
109122
.workspace(workspace)
123+
.threadJournalStore(new InMemoryThreadJournalStore())
110124
.model(model)
111125
.toolkit(toolkit)
112126
.disableDefaultWorkspaceSkills()
@@ -231,6 +245,7 @@ && new String(file.getValue(), StandardCharsets.UTF_8)
231245
.abstractFilesystem(filesystem)
232246
.messageBus(bus)
233247
.journalEnabled(journalEnabled)
248+
.threadJournalStore(new InMemoryThreadJournalStore())
234249
.model(model)
235250
.disableDefaultWorkspaceSkills()
236251
.compaction(
@@ -335,6 +350,7 @@ void newSubagentResultIsReadableByLegacyInbox() {
335350
var sender =
336351
HarnessAgent.builder()
337352
.workspace(workspace)
353+
.threadJournalStore(new InMemoryThreadJournalStore())
338354
.abstractFilesystem(filesystem)
339355
.messageBus(bus)
340356
.model(new MockModel("unused"))
@@ -434,6 +450,7 @@ void smallSkillCatalogSupportsDirectLoading(boolean dynamicSkills) throws Except
434450
HarnessAgent.builder()
435451
.model(model)
436452
.workspace(workspace)
453+
.threadJournalStore(new InMemoryThreadJournalStore())
437454
.abstractFilesystem(new LocalFilesystem(workspace))
438455
.disableSubagents()
439456
.disableCompaction();
@@ -526,6 +543,7 @@ void compactionFlushRequiresMemoryOptIn(
526543
.workspace(workspace)
527544
.abstractFilesystem(new LocalFilesystem(workspace))
528545
.journalEnabled(journal)
546+
.threadJournalStore(new InMemoryThreadJournalStore())
529547
.disableDefaultWorkspaceSkills()
530548
.disableMemoryHooks()
531549
.compaction(
@@ -609,6 +627,7 @@ void dynamicSpawnResumesInNewRuntimeContext(boolean allow) throws Exception {
609627
try (var agent =
610628
HarnessAgent.builder()
611629
.workspace(workspace)
630+
.threadJournalStore(new InMemoryThreadJournalStore())
612631
.model(model)
613632
.abstractFilesystem(new LocalFilesystem(workspace))
614633
.disableDefaultWorkspaceSkills()
@@ -657,6 +676,7 @@ void memoryToolVisibilityInheritedByBothFactories(boolean memory, boolean disabl
657676
HarnessAgent.builder()
658677
.model(new MockModel("ok"))
659678
.workspace(workspace)
679+
.threadJournalStore(new InMemoryThreadJournalStore())
660680
.disableDefaultWorkspaceSkills()
661681
.disableMemoryHooks();
662682
if (memory) builder.enableLongTermMemory();

‎agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/local/LocalFilesystemWithShellTest.java‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.nio.charset.StandardCharsets;
4242
import java.nio.file.Files;
4343
import java.nio.file.Path;
44+
import java.nio.file.StandardCopyOption;
4445
import java.nio.file.StandardWatchEventKinds;
4546
import java.security.DigestInputStream;
4647
import java.security.MessageDigest;
@@ -577,6 +578,7 @@ void execute_interruptTerminatesLocalProcessTreeAndDrainers(@TempDir Path tempDi
577578
worker.interrupt();
578579
worker.join(TimeUnit.SECONDS.toMillis(60));
579580
}
581+
awaitDirectoryReleased(tempDir);
580582
}
581583

582584
@Test
@@ -598,6 +600,7 @@ void execute_timeoutTerminatesLocalParentAndChild(@TempDir Path tempDir) throws
598600
ProcessHandle.of(pid).ifPresent(ProcessHandle::destroyForcibly);
599601
}
600602
}
603+
awaitDirectoryReleased(tempDir);
601604
}
602605

603606
@Test
@@ -642,6 +645,35 @@ void execute_reactorCancellationInterruptsAndCleansLocalTree(@TempDir Path tempD
642645
}
643646
scheduler.dispose();
644647
}
648+
awaitDirectoryReleased(tempDir);
649+
}
650+
651+
/**
652+
* On Windows a forcibly terminated process reports as dead before its working-directory handle
653+
* is released, and the fixture processes above run with the temp directory as their working
654+
* directory, so JUnit's deletion of that directory right after the test can fail with "being
655+
* used by another process" while a killed JVM is still being torn down: #4523 and main run
656+
* 46571815777, both windows-latest on 2026-12-01, one sibling test each. Renaming the directory
657+
* is refused by the same hold, so poll it instead of sleeping; the first attempt succeeds
658+
* unless the hold is still open.
659+
*/
660+
private static void awaitDirectoryReleased(Path directory)
661+
throws IOException, InterruptedException {
662+
Path probe = directory.resolveSibling(directory.getFileName() + ".release-probe");
663+
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(60);
664+
while (true) {
665+
try {
666+
Files.move(directory, probe, StandardCopyOption.ATOMIC_MOVE);
667+
} catch (IOException stillHeld) {
668+
assertTrue(
669+
System.nanoTime() < deadline,
670+
"workspace still in use after cleanup: " + stillHeld);
671+
Thread.sleep(20);
672+
continue;
673+
}
674+
Files.move(probe, directory, StandardCopyOption.ATOMIC_MOVE);
675+
return;
676+
}
645677
}
646678

647679
private static void assertProcessesStopped(List<Long> pids, Set<String> existingDrainers) {

‎agentscope-harness/src/test/java/io/agentscope/harness/agent/gateway/HarnessGatewayEventPublicationTest.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import io.agentscope.core.agent.RuntimeContext;
3030
import io.agentscope.core.event.AgentResultEvent;
31+
import io.agentscope.core.journal.InMemoryThreadJournalStore;
3132
import io.agentscope.core.message.Msg;
3233
import io.agentscope.core.message.MsgRole;
3334
import io.agentscope.core.message.TextBlock;
@@ -56,6 +57,12 @@
5657

5758
class HarnessGatewayEventPublicationTest {
5859

60+
/**
61+
* The agent runs on an ephemeral {@link InMemoryThreadJournalStore}: the test asserts gateway
62+
* wakeup semantics, not journal persistence, and the default workspace journal is SQLite on
63+
* Windows, where this test took 0.99-8.67s when green against 0.15-0.32s on ubuntu, and #2871
64+
* (2026-12-01, windows-latest) crossed {@code turn.get(5s)}.
65+
*/
5966
@Test
6067
void completionsDuringTheFinalModelCallWakeOnceAfterTheTurn(@TempDir java.nio.file.Path dir)
6168
throws Exception {
@@ -101,6 +108,7 @@ public Flux<ChatResponse> stream(
101108
.name("main")
102109
.model(model)
103110
.workspace(dir.resolve("agent"))
111+
.threadJournalStore(new InMemoryThreadJournalStore())
104112
.messageBus(bus)
105113
.disableSubagents()
106114
.build();

‎agentscope-harness/src/test/java/io/agentscope/harness/agent/tool/WaitAsyncResultsToolTest.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.List;
4141
import java.util.Map;
4242
import java.util.concurrent.CompletableFuture;
43+
import java.util.concurrent.CopyOnWriteArrayList;
4344
import java.util.concurrent.CountDownLatch;
4445
import java.util.concurrent.TimeUnit;
4546
import java.util.concurrent.atomic.AtomicBoolean;
@@ -678,10 +679,15 @@ public boolean cancelTask(RuntimeContext rc, String sessionId, String taskId) {
678679
}
679680
}
680681

682+
/**
683+
* The completer thread appends while the tool thread polls this list from {@code getTask()}, so
684+
* a plain {@link ArrayList} threw ConcurrentModificationException in #4471 (2026-11-28), #4395
685+
* and main run 46441604698 (both 2026-11-30), all windows-latest.
686+
*/
681687
private static class MutableTaskRepository extends StubTaskRepository {
682688

683689
MutableTaskRepository(List<BackgroundTask> tasks) {
684-
super(new ArrayList<>(tasks));
690+
super(new CopyOnWriteArrayList<>(tasks));
685691
}
686692

687693
void add(BackgroundTask task) {

0 commit comments

Comments
 (0)