From 9221550a2a55e97187f7317aaa4201528fb90253 Mon Sep 17 00:00:00 2001 From: mhoennig Date: Thu, 3 Sep 2026 19:32:22 +0200 Subject: [PATCH] test(build): gate the maxConcurrent-1 test instead of racing a sleep The build of branch-a slept one second while the test asserted, without any synchronization, that branch-b was still PENDING. Under CPU contention on the mih09 host the sleep could elapse first, so branch-b was already RUNNING or SUCCESS when the assertion ran. branch-a now blocks until the test creates a gate file, and the test first waits for branch-a to be RUNNING; the PENDING assertion no longer depends on timing. Co-Authored-By: Claude Opus 5 --- .../de/hoennig/werkator/build/BuildExecutorTest.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/de/hoennig/werkator/build/BuildExecutorTest.kt b/src/test/kotlin/de/hoennig/werkator/build/BuildExecutorTest.kt index 1174a1f..cb6a0a9 100644 --- a/src/test/kotlin/de/hoennig/werkator/build/BuildExecutorTest.kt +++ b/src/test/kotlin/de/hoennig/werkator/build/BuildExecutorTest.kt @@ -505,6 +505,8 @@ class BuildExecutorTest : FunSpec() { } test("with maxConcurrent 1 a second branch stays PENDING until the first finished") { + // branch-a blocks on a gate file the test creates, so the PENDING assertion + // below cannot race the first build finishing on a loaded machine val h = Harness( """ @@ -512,7 +514,7 @@ class BuildExecutorTest : FunSpec() { maxConcurrent: 1 branches: branch-a: - buildCommand: "sleep 1" + buildCommand: "until [ -f gate ]; do sleep 0.05; done" cleanCommand: "" branch-b: buildCommand: "echo ok" @@ -523,8 +525,13 @@ class BuildExecutorTest : FunSpec() { h.executor.startBuild(h.repo, "branch-a", "sha-a") h.executor.startBuild(h.repo, "branch-b", "sha-b") + eventually(30.seconds) { + h.repository.latestFor("branch-a")?.status shouldBe BuildStatus.RUNNING + } h.repository.latestFor("branch-b")?.status shouldBe BuildStatus.PENDING + Files.createFile(h.workingDir.resolve("gate")) + awaitStatus(h, "branch-b", BuildStatus.SUCCESS) awaitStatus(h, "branch-a", BuildStatus.SUCCESS) val transitions = h.events.map { it.result.branch to it.result.status }