|
8 | 8 |
|
9 | 9 | import com.cloudbees.jenkins.support.SupportTestUtils;
|
10 | 10 | 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; |
11 | 18 | import org.junit.Rule;
|
12 | 19 | import org.junit.Test;
|
13 | 20 | import org.jvnet.hudson.test.InboundAgentRule;
|
14 | 21 | import org.jvnet.hudson.test.JenkinsRule;
|
| 22 | +import org.jvnet.hudson.test.TestExtension; |
15 | 23 |
|
16 | 24 | public class SlaveLaunchLogsTest {
|
17 | 25 |
|
| 26 | + static { |
| 27 | + StandardOutputSwapper.disabled = true; // TODO JENKINS-65582 noisy |
| 28 | + // TODO also suppress JnlpSlaveRestarterInstaller |
| 29 | + } |
| 30 | + |
18 | 31 | @Rule
|
19 | 32 | public JenkinsRule j = new JenkinsRule();
|
20 | 33 |
|
@@ -65,11 +78,51 @@ public void offlineAgent() throws Exception {
|
65 | 78 | "still includes something",
|
66 | 79 | SupportTestUtils.invokeComponentToMap(ExtensionList.lookupSingleton(SlaveLaunchLogs.class))
|
67 | 80 | .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 | + } |
69 | 124 | }
|
70 | 125 |
|
71 |
| - // TODO logs from a deleted agent |
72 |
| - // TODO logs from multiple launch attempts of same agent |
73 | 126 | // TODO honor SafeTimerTask.getLogsRoot (if applicable)
|
74 | 127 | // TODO rotation of old or excessively long logs
|
75 | 128 |
|
|
0 commit comments