Reduce test flakiness (#10809)
Changelog Drafter / update_draft_release (push) Waiting to run Details
Changelog Drafter / jenkins_io_draft (push) Waiting to run Details
Label conflicting PRs / main (push) Waiting to run Details

* Reduce inQueueTaskLookupByAPI flakiness

https://app.launchableinc.com/organizations/jenkins/workspaces/jenkins/data/test-paths/class%3Dhudson.model.QueueTest%23%23%23testcase%3DinQueueTaskLookupByAPI?dateFilter=90d
reports that inQueueTaskLookupByAPI has been flaky in th epast 90 days.
The flakiness seems to be specific to Windows and seems to be related to
the job not be in the queue quickly enough after the call toe schedule
the build.

If the job is not queued, sleep for 3 seonds to allow it time to queue.

Testing done:

Confirmed that the job queues consistently on my Linux computer, so the
sleep statement is not executed.

* Replace SCSS 1x with 1dppx to silence HTMLUnit warning

Per https://developer.mozilla.org/en-US/docs/Web/CSS/resolution , `x` is
an alias for `dppx`, so let's use `dppx` to avoid warnings from HTMLUnit.

* Reduce flakiness of ComputerStateTest#testUiForConnected

https://app.launchableinc.com/organizations/jenkins/workspaces/jenkins/data/test-paths/class%3Dhudson.cli.ComputerStateTest%23%23%23testcase%3DtestUiForConnected?dateFilter=90d
reports that there have been multiple failures of
ComputerStateTest#testUiForConnected in the last 90 days.  The failures
seem to be related to a race condition that the agent is not yet
disconnected when the state of the agent is checked.  Wait for 1 second
to allow the agent to disconnect before checking agent status.

The average time to run the test is 34 seconds.  This will increase that
average time by 1 second.  Not a significant increase compared to the
benefit of avoiding a flaky test.

* Reduce preventXssInBadgeTooltip flakes with a 2 second sleep

https://app.launchableinc.com/organizations/jenkins/workspaces/jenkins/data/test-paths/class%3Dhudson.model.RunTest%23%23%23testcase%3DpreventXssInBadgeTooltip?dateFilter=90d
shows there have been random test failures of preventXssInBadgeTooltip
in the last 90 days.

Reeduce failures by sleeping before the key assertions in order to allow
Jenkins to complete the initialization of the page.
This commit is contained in:
Mark Waite 2025-07-07 18:45:58 -06:00 committed by GitHub
parent f610669e01
commit f59a5d4536
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 1 deletions

View File

@ -138,7 +138,7 @@ $semantics: (
--jenkins-border--subtle-shadow: 0 0 0 var(--jenkins-border-width)
var(--jenkins-border-color--subtle);
@media (resolution <= 1x) {
@media (resolution <= 1dppx) {
--jenkins-border-width: 2px;
}

View File

@ -154,6 +154,9 @@ class ComputerStateTest {
slave.toComputer().disconnect(null);
// Test fails sometimes because agent is not yet disconnected
// Wait 1 second for disconnect to complete
Thread.sleep(1009);
HtmlPage page = wc.getPage(slave);
assertLinkDoesNotExist(page, "Disconnect");

View File

@ -462,6 +462,13 @@ public class QueueTest {
p.setAssignedLabel(label);
p.scheduleBuild2(0);
// Wait 3 seconds if job is not already in the queue, reduce test flakes
if (!p.isInQueue()) {
Thread.sleep(3000);
}
assertTrue(p.isInQueue(), "Build not queued");
JenkinsRule.WebClient webclient = r.createWebClient();
XmlPage queueItems = webclient.goToXml("queue/api/xml");

View File

@ -196,6 +196,9 @@ class RunTest {
// keeping the minimum to validate it's working and it's not exploitable as there are some modifications
// like adding double quotes
// Some test flakes due to JavaScript objects not yet available
// Wait 2 seconds before checking the assertion
Thread.sleep(2003);
ensureXssIsPrevented(up, "Down", "<img");
}