Skip to content

Commit d072846

Browse files
committed
More robust way to wait for Connection terminated message
1 parent 72beede commit d072846

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@
154154
</exclusion>
155155
</exclusions>
156156
</dependency>
157+
<dependency>
158+
<groupId>org.awaitility</groupId>
159+
<artifactId>awaitility</artifactId>
160+
<version>4.2.0</version>
161+
<scope>test</scope>
162+
</dependency>
157163
<!-- MockFolder that was used for SupportAbstractItem test does not have UI, hence need full Folder implementation.-->
158164
<dependency>
159165
<groupId>org.jenkins-ci.plugins</groupId>

src/test/java/com/cloudbees/jenkins/support/impl/SlaveLaunchLogsTest.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cloudbees.jenkins.support.impl;
22

3+
import static org.awaitility.Awaitility.await;
34
import static org.hamcrest.MatcherAssert.assertThat;
45
import static org.hamcrest.Matchers.allOf;
56
import static org.hamcrest.Matchers.containsString;
@@ -80,7 +81,10 @@ public void offlineAgent() throws Exception {
8081
public void deletedAgent() throws Exception {
8182
var s = j.createOnlineSlave();
8283
s.toComputer().disconnect(null).get();
83-
Thread.sleep(1000); // TODO otherwise log is not flushed?
84+
await().until(
85+
() -> SupportTestUtils.invokeComponentToString(
86+
ExtensionList.lookupSingleton(SlaveLaunchLogs.class)),
87+
containsString("Connection terminated"));
8488
j.jenkins.removeNode(s);
8589
assertThat(
8690
"still includes something",
@@ -92,7 +96,10 @@ public void deletedAgent() throws Exception {
9296
public void multipleLaunchLogs() throws Exception {
9397
var s = j.createOnlineSlave();
9498
s.toComputer().disconnect(null).get();
95-
Thread.sleep(1000); // TODO as above
99+
await().until(
100+
() -> SupportTestUtils.invokeComponentToString(
101+
ExtensionList.lookupSingleton(SlaveLaunchLogs.class)),
102+
containsString("Connection terminated"));
96103
s.toComputer().connect(false).get();
97104
assertThat(
98105
"notes both launch logs",

0 commit comments

Comments
 (0)