Skip to content

Commit 2a9b6e1

Browse files
committed
JenkinsSessionRule seems to solve that issue
1 parent cb46c86 commit 2a9b6e1

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

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

+50-50
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,28 @@
1111
import java.nio.file.StandardOpenOption;
1212
import java.util.Map;
1313
import org.junit.After;
14-
import org.junit.AfterClass;
15-
import org.junit.BeforeClass;
14+
import org.junit.Before;
1615
import org.junit.Rule;
1716
import org.junit.Test;
18-
import org.jvnet.hudson.test.JenkinsRule;
17+
import org.jvnet.hudson.test.JenkinsSessionRule;
1918

2019
/**
2120
* Tests for the {@link NodeRemoteDirectoryComponent}
2221
*/
2322
public class NodeRemoteDirectoryComponentTest {
2423

2524
@Rule
26-
public JenkinsRule j = new JenkinsRule();
25+
public JenkinsSessionRule r = new JenkinsSessionRule();
2726

28-
@BeforeClass
29-
public static void clearLog() throws Exception {
27+
@Before
28+
public void clearLog() throws Throwable {
3029
try (var os =
3130
Files.newOutputStream(SafeLog.file, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {}
3231
System.err.println("Cleared " + SafeLog.file);
3332
}
3433

3534
@After
36-
public void showLog() throws Exception {
37-
System.err.println("---%<--- " + SafeLog.file);
38-
Files.copy(SafeLog.file, System.err);
39-
System.err.println("--->%--- ");
40-
}
41-
42-
@AfterClass
43-
public static void showFinalLog() throws Exception {
35+
public void showLog() throws Throwable {
4436
System.err.println("---%<--- " + SafeLog.file);
4537
Files.copy(SafeLog.file, System.err);
4638
System.err.println("--->%--- ");
@@ -50,61 +42,69 @@ public static void showFinalLog() throws Exception {
5042
* Test adding agent remote directory content with the defaults.
5143
*/
5244
@Test
53-
public void addContents() throws Exception {
54-
DumbSlave agent = j.createOnlineSlave(Label.parseExpression("test"), null);
45+
public void addContents() throws Throwable {
46+
r.then(j -> {
47+
DumbSlave agent = j.createOnlineSlave(Label.parseExpression("test"), null);
5548

56-
Map<String, String> output =
57-
SupportTestUtils.invokeComponentToMap(new NodeRemoteDirectoryComponent(), agent.toComputer());
49+
Map<String, String> output =
50+
SupportTestUtils.invokeComponentToMap(new NodeRemoteDirectoryComponent(), agent.toComputer());
5851

59-
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
60-
assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
52+
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
53+
assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
54+
});
6155
}
6256

6357
/*
6458
* Test adding agent remote directory content with excludes pattern(s).
6559
*/
6660
@Test
67-
public void addContentsWithExcludes() throws Exception {
68-
DumbSlave agent = j.createSlave("agent1", "test", null);
69-
agent.getComputer().connect(false).get();
70-
j.waitOnline(agent);
71-
72-
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
73-
new NodeRemoteDirectoryComponent("", "**/*.log", true, 10), agent.toComputer());
74-
75-
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
76-
assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + ".*/.*.log")));
61+
public void addContentsWithExcludes() throws Throwable {
62+
r.then(j -> {
63+
DumbSlave agent = j.createSlave("agent1", "test", null);
64+
agent.getComputer().connect(false).get();
65+
j.waitOnline(agent);
66+
67+
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
68+
new NodeRemoteDirectoryComponent("", "**/*.log", true, 10), agent.toComputer());
69+
70+
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
71+
assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + ".*/.*.log")));
72+
});
7773
}
7874

7975
/*
8076
* Test adding agent remote directory content with includes pattern(s).
8177
*/
8278
@Test
83-
public void addContentsWithIncludes() throws Exception {
84-
DumbSlave agent = j.createSlave("agent1", "test", null);
85-
agent.getComputer().connect(false).get();
86-
j.waitOnline(agent);
87-
88-
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
89-
new NodeRemoteDirectoryComponent("support/*.log", "", true, 10), agent.toComputer());
90-
91-
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
92-
assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
79+
public void addContentsWithIncludes() throws Throwable {
80+
r.then(j -> {
81+
DumbSlave agent = j.createSlave("agent1", "test", null);
82+
agent.getComputer().connect(false).get();
83+
j.waitOnline(agent);
84+
85+
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
86+
new NodeRemoteDirectoryComponent("support/*.log", "", true, 10), agent.toComputer());
87+
88+
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
89+
assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
90+
});
9391
}
9492

9593
/*
9694
* Test adding agent remote directory content with includes pattern(s).
9795
*/
9896
@Test
99-
public void addContentsWithMaxDepth() throws Exception {
100-
DumbSlave agent = j.createSlave("agent1", "test", null);
101-
agent.getComputer().connect(false).get();
102-
j.waitOnline(agent);
103-
104-
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
105-
new NodeRemoteDirectoryComponent("", "", true, 1), agent.toComputer());
106-
107-
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
108-
assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
97+
public void addContentsWithMaxDepth() throws Throwable {
98+
r.then(j -> {
99+
DumbSlave agent = j.createSlave("agent1", "test", null);
100+
agent.getComputer().connect(false).get();
101+
j.waitOnline(agent);
102+
103+
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
104+
new NodeRemoteDirectoryComponent("", "", true, 1), agent.toComputer());
105+
106+
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
107+
assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
108+
});
109109
}
110110
}

0 commit comments

Comments
 (0)