From dbac6d39baa2ce896904cb9fa12d326a4d4c2ec9 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 31 May 2025 03:40:46 -0800 Subject: [PATCH] Accept UserIdCause or LegacyCodeCause in disconnectCause test (#10700) * Accept UserIdCause or LegacyCodeCause in disconnectCause test The hudson.model.ExecutorTest.disconnectCause() test fails in up to 10% of jobs on ci.jenkins.io because the cause is a LegacyCodeCause instead of the expected UserIdCause. In my 140 runs on my local Linux computer, I never saw a LegacyCodeCause, but it seems safe to check one of two failure messages rather than fail the test. * Fix compilation error --- test/src/test/java/hudson/model/ExecutorTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/src/test/java/hudson/model/ExecutorTest.java b/test/src/test/java/hudson/model/ExecutorTest.java index fb5f48c671..7d5f689edc 100644 --- a/test/src/test/java/hudson/model/ExecutorTest.java +++ b/test/src/test/java/hudson/model/ExecutorTest.java @@ -3,6 +3,7 @@ package hudson.model; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; @@ -121,7 +122,14 @@ public class ExecutorTest { j.assertLogContains("Finished: FAILURE", b); j.assertLogContains("Build step 'TestBuilder' marked build as failure", b); j.assertLogContains("Agent went offline during the build", b); - j.assertLogContains("Disconnected by Johnny : Taking offline to break your build", b); + // The test reports a legacy code cause in up to 10% of jobs on ci.jenkins.io. + // Accept either cause and assert the expected message for each type of cause. + if (p.getLastBuild().getCause(Cause.class) instanceof Cause.UserIdCause) { + j.assertLogContains("Disconnected by Johnny : Taking offline to break your build", b); + } else { + assertThat(p.getLastBuild().getCause(Cause.class), instanceOf(Cause.LegacyCodeCause.class)); + j.assertLogContains((new Cause.LegacyCodeCause()).getShortDescription(), b); + } } @Issue("SECURITY-611")