Skip to content

Commit 57a4a43

Browse files
authored
fix: Make chaosOnRestart test more reliable (#985)
- Reduce resource count from 50 to 5 to reduce non-determinism - Wait for b2's semaphores to start before releasing them - Use waitForCompletion() and assertBuildStatusSuccess() for proper build completion verification instead of waitForMessage() The test was flaky due to timing issues with 50 parallel resources and nested locks across 3 builds resuming after Jenkins restart.
1 parent 1ab8074 commit 57a4a43

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/test/java/org/jenkins/plugins/lockableresources/LockStepWithRestartTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ void checkQueueAfterRestart() throws Throwable {
201201

202202
@Test
203203
void chaosOnRestart() throws Throwable {
204-
final int resourceCount = 50;
204+
// Reduced from 50 to 5 resources to make the test more deterministic
205+
// while still testing the same restart scenarios with parallel stages
206+
final int resourceCount = 5;
205207
sessions.then(j -> {
206208
for (int i = 1; i <= resourceCount; i++) {
207209
LockableResourcesManager.get().createResourceWithLabel("resource" + i, "label");
@@ -238,13 +240,15 @@ void chaosOnRestart() throws Throwable {
238240
WorkflowRun b2 = p.getBuildByNumber(2);
239241
WorkflowRun b3 = p.getBuildByNumber(3);
240242

241-
// Unlock resources
243+
// Unlock resources for b1
242244
for (int i = 1; i <= resourceCount; i++) {
243245
SemaphoreStep.success("wait-inside-lockOrderRestart-" + i + "/1", null);
244246
}
245247
j.waitForMessage("Lock released on resource [Resource: resource" + resourceCount + "]", b1);
246248
j.waitForMessage("Lock acquired on [Resource: resource" + resourceCount + "]", b2);
247249
j.assertLogContains("[resource" + resourceCount + "] is locked by build " + b1.getFullDisplayName(), b3);
250+
// Wait for b2 to reach all semaphores before releasing them
251+
SemaphoreStep.waitForStart("wait-inside-lockOrderRestart-" + resourceCount + "/2", b2);
248252
for (int i = 1; i <= resourceCount; i++) {
249253
SemaphoreStep.success("wait-inside-lockOrderRestart-" + i + "/2", null);
250254
}
@@ -253,7 +257,13 @@ void chaosOnRestart() throws Throwable {
253257
for (int i = 1; i <= resourceCount; i++) {
254258
SemaphoreStep.success("wait-inside-lockOrderRestart-" + i + "/3", null);
255259
}
256-
j.waitForMessage("Finish", b3);
260+
// Wait for all builds to complete
261+
j.waitForCompletion(b1);
262+
j.waitForCompletion(b2);
263+
j.waitForCompletion(b3);
264+
j.assertBuildStatusSuccess(b1);
265+
j.assertBuildStatusSuccess(b2);
266+
j.assertBuildStatusSuccess(b3);
257267
});
258268
}
259269
}

0 commit comments

Comments
 (0)