-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow port reuse in RestartableJenkinsRule
Testing the Swarm client requires having Jenkins run on the same port before and after restart. This change adds this functionality to RestartableJenkinsRule. The new functionality is opt-in to preserve existing behavior for tests which don't need this functionality.
- Loading branch information
Showing
3 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/org/jvnet/hudson/test/RestartableJenkinsRuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.jvnet.hudson.test; | ||
|
||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assume.assumeThat; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class RestartableJenkinsRuleTest { | ||
|
||
@Rule public RestartableJenkinsRule noPortReuse = new RestartableJenkinsRule(); | ||
|
||
@Rule | ||
public RestartableJenkinsRule portReuse = | ||
new RestartableJenkinsRule.Builder().withReusedPort().build(); | ||
|
||
@Test | ||
public void testNoPortReuse() throws Exception { | ||
assumeThat( | ||
"This test requires a custom port to not be set.", | ||
System.getProperty("port"), | ||
nullValue()); | ||
|
||
AtomicInteger port = new AtomicInteger(); | ||
noPortReuse.then( | ||
s -> { | ||
port.set(noPortReuse.j.getURL().getPort()); | ||
}); | ||
noPortReuse.then( | ||
s -> { | ||
assertNotEquals(port.get(), noPortReuse.j.getURL().getPort()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testPortReuse() throws Exception { | ||
assumeThat( | ||
"This test requires a custom port to not be set.", | ||
System.getProperty("port"), | ||
nullValue()); | ||
|
||
AtomicInteger port = new AtomicInteger(); | ||
portReuse.then( | ||
s -> { | ||
port.set(portReuse.j.getURL().getPort()); | ||
}); | ||
portReuse.then( | ||
s -> { | ||
assertEquals(port.get(), portReuse.j.getURL().getPort()); | ||
}); | ||
} | ||
} |