Skip to content

Commit 3d0a97a

Browse files
committed
Exploring SlaveLaunchLogs behavior
1 parent 0cd0f81 commit 3d0a97a

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

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

+56-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,26 @@
88

99
import com.cloudbees.jenkins.support.SupportTestUtils;
1010
import hudson.ExtensionList;
11+
import hudson.model.Computer;
12+
import hudson.model.TaskListener;
13+
import hudson.slaves.ComputerListener;
14+
import hudson.slaves.SlaveComputer;
15+
import java.io.IOException;
16+
import jenkins.slaves.StandardOutputSwapper;
17+
import org.junit.Ignore;
1118
import org.junit.Rule;
1219
import org.junit.Test;
1320
import org.jvnet.hudson.test.InboundAgentRule;
1421
import org.jvnet.hudson.test.JenkinsRule;
22+
import org.jvnet.hudson.test.TestExtension;
1523

1624
public class SlaveLaunchLogsTest {
1725

26+
static {
27+
StandardOutputSwapper.disabled = true; // TODO JENKINS-65582 noisy
28+
// TODO also suppress JnlpSlaveRestarterInstaller
29+
}
30+
1831
@Rule
1932
public JenkinsRule j = new JenkinsRule();
2033

@@ -65,11 +78,51 @@ public void offlineAgent() throws Exception {
6578
"still includes something",
6679
SupportTestUtils.invokeComponentToMap(ExtensionList.lookupSingleton(SlaveLaunchLogs.class))
6780
.get("nodes/slave/" + name + "/launchLogs/slave.log"),
68-
allOf(notNullValue(), containsString("Remoting version: ")));
81+
allOf(notNullValue(), containsString("Remoting version: "), containsString("Connection terminated")));
82+
}
83+
84+
@Ignore("TODO not sure how to archive the logs before deletion from SlaveComputer.kill")
85+
@Test
86+
public void deletedAgent() throws Exception {
87+
var s = j.createOnlineSlave();
88+
var name = s.getNodeName();
89+
s.toComputer().disconnect(null).get();
90+
j.jenkins.removeNode(s);
91+
assertThat(
92+
"still includes something",
93+
SupportTestUtils.invokeComponentToString(ExtensionList.lookupSingleton(SlaveLaunchLogs.class)),
94+
allOf(notNullValue(), containsString("Remoting version: "), containsString("Connection terminated")));
95+
}
96+
97+
@Test
98+
public void multipleLaunchLogs() throws Exception {
99+
var s = j.createOnlineSlave();
100+
var name = s.getNodeName();
101+
s.toComputer().disconnect(null).get();
102+
Thread.sleep(1000); // TODO otherwise log is not flushed?
103+
s.toComputer().connect(false).get();
104+
assertThat(
105+
"notes both launch logs",
106+
SupportTestUtils.invokeComponentToString(ExtensionList.lookupSingleton(SlaveLaunchLogs.class)),
107+
allOf(
108+
notNullValue(),
109+
containsString("Launch attempt #1"),
110+
containsString("Connection terminated"),
111+
containsString("Launch attempt #2")));
112+
}
113+
114+
@TestExtension("multipleLaunchLogs")
115+
public static final class DistinctiveLaunchMessage extends ComputerListener {
116+
int count;
117+
118+
@Override
119+
public void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException {
120+
if (c instanceof SlaveComputer) {
121+
listener.getLogger().println("Launch attempt #" + ++count);
122+
}
123+
}
69124
}
70125

71-
// TODO logs from a deleted agent
72-
// TODO logs from multiple launch attempts of same agent
73126
// TODO honor SafeTimerTask.getLogsRoot (if applicable)
74127
// TODO rotation of old or excessively long logs
75128

0 commit comments

Comments
 (0)