Skip to content

Commit 5abdacd

Browse files
Add retry to flaky test in ResponseTimeMonitorTest (jenkinsci#10654)
* Add retry to flaky test in ResponseTimeMonitorTest * Retry with awaitility * Update test/src/test/java/hudson/node_monitors/ResponseTimeMonitorTest.java Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com> --------- Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
1 parent 03bc1db commit 5abdacd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

test/src/test/java/hudson/node_monitors/ResponseTimeMonitorTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package hudson.node_monitors;
22

3+
import static org.awaitility.Awaitility.await;
34
import static org.junit.Assert.assertEquals;
45
import static org.junit.Assert.assertNotNull;
56
import static org.junit.Assert.assertNull;
@@ -11,6 +12,8 @@
1112
import hudson.slaves.DumbSlave;
1213
import hudson.slaves.OfflineCause;
1314
import hudson.slaves.SlaveComputer;
15+
import java.util.concurrent.ExecutionException;
16+
import java.util.concurrent.TimeUnit;
1417
import org.junit.Rule;
1518
import org.junit.Test;
1619
import org.jvnet.hudson.test.InboundAgentRule;
@@ -47,8 +50,15 @@ public void skipOfflineAgent() throws Exception {
4750
j.disconnectSlave(s);
4851
assertNull(ResponseTimeMonitor.DESCRIPTOR.monitor(c));
4952

50-
// Now reconnect and make sure we get a non-null response.
51-
c.connect(false).get(); // wait until it's connected
53+
// Retry to compensate for test being flaky in CI
54+
await().atMost(5, TimeUnit.SECONDS)
55+
.ignoreException(ExecutionException.class)
56+
.until(() -> {
57+
// Now reconnect and make sure we get a non-null response.
58+
c.connect(false).get(); // wait until it's connected
59+
return true;
60+
}
61+
);
5262

5363
assertNotNull(ResponseTimeMonitor.DESCRIPTOR.monitor(c));
5464
}

0 commit comments

Comments
 (0)