mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
Merge branch 'master' into node-cli
This commit is contained in:
commit
b74185f133
225 files changed
+4877
-935
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package org.jvnet.hudson.test;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Computer;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.remoting.Channel;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import hudson.slaves.ComputerListener;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Runs at the end of the test to cleanup any live channels.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
@Extension
|
||||
public class ChannelShutdownListener extends ComputerListener implements EndOfTestListener {
|
||||
/**
|
||||
* Remember channels that are created, to release them at the end.
|
||||
*/
|
||||
private List<Channel> channels = new ArrayList<Channel>();
|
||||
|
||||
@Override
|
||||
public synchronized void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException {
|
||||
VirtualChannel ch = c.getChannel();
|
||||
if (ch instanceof Channel) {
|
||||
channels.add((Channel)ch);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onTearDown() throws Exception {
|
||||
for (Channel c : channels)
|
||||
c.close();
|
||||
for (Channel c : channels)
|
||||
c.join();
|
||||
channels.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.jvnet.hudson.test;
|
||||
|
||||
import hudson.ExtensionPoint;
|
||||
|
||||
/**
|
||||
* Gets notified before the test completes to perform additional cleanup.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @since 1.520
|
||||
*/
|
||||
public interface EndOfTestListener extends ExtensionPoint {
|
||||
/**
|
||||
* Called for clean up.
|
||||
*/
|
||||
void onTearDown() throws Exception;
|
||||
}
|
||||
@@ -57,8 +57,6 @@ import hudson.model.*;
|
||||
import hudson.model.Executor;
|
||||
import hudson.model.Node.Mode;
|
||||
import hudson.model.Queue.Executable;
|
||||
import hudson.remoting.Channel;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import hudson.remoting.Which;
|
||||
import hudson.security.ACL;
|
||||
import hudson.security.AbstractPasswordBasedSecurityRealm;
|
||||
@@ -77,7 +75,6 @@ import hudson.tasks.BuildWrapper;
|
||||
import hudson.tasks.BuildWrapperDescriptor;
|
||||
import hudson.tasks.Builder;
|
||||
import hudson.tasks.Mailer;
|
||||
import hudson.tasks.Mailer.DescriptorImpl;
|
||||
import hudson.tasks.Maven;
|
||||
import hudson.tasks.Maven.MavenInstallation;
|
||||
import hudson.tasks.Publisher;
|
||||
@@ -177,7 +174,6 @@ import com.gargoylesoftware.htmlunit.DefaultCssErrorHandler;
|
||||
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
|
||||
import com.gargoylesoftware.htmlunit.Page;
|
||||
import com.gargoylesoftware.htmlunit.WebRequestSettings;
|
||||
import com.gargoylesoftware.htmlunit.WebResponse;
|
||||
import com.gargoylesoftware.htmlunit.html.DomNode;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlButton;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlElement;
|
||||
@@ -195,7 +191,9 @@ import jenkins.model.JenkinsLocationConfiguration;
|
||||
*
|
||||
* @see <a href="http://wiki.jenkins-ci.org/display/JENKINS/Unit+Test">Wiki article about unit testing in Hudson</a>
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @deprecated New code should use {@link JenkinsRule}.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("rawtypes")
|
||||
public abstract class HudsonTestCase extends TestCase implements RootAction {
|
||||
/**
|
||||
@@ -232,11 +230,6 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
|
||||
*/
|
||||
private List<WebClient> clients = new ArrayList<WebClient>();
|
||||
|
||||
/**
|
||||
* Remember channels that are created, to release them at the end.
|
||||
*/
|
||||
private List<Channel> channels = new ArrayList<Channel>();
|
||||
|
||||
/**
|
||||
* JavaScript "debugger" that provides you information about the JavaScript call stack
|
||||
* and the current values of the local variables in those stack frame.
|
||||
@@ -388,6 +381,11 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
if (jenkins!=null) {
|
||||
for (EndOfTestListener tl : jenkins.getExtensionList(EndOfTestListener.class))
|
||||
tl.onTearDown();
|
||||
}
|
||||
|
||||
if (timeoutTimer!=null) {
|
||||
timeoutTimer.cancel();
|
||||
timeoutTimer = null;
|
||||
@@ -400,15 +398,6 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
|
||||
client.closeAllWindows();
|
||||
}
|
||||
clients.clear();
|
||||
|
||||
synchronized(channels) {
|
||||
for (Channel c : channels)
|
||||
c.close();
|
||||
for (Channel c : channels)
|
||||
c.join();
|
||||
channels.clear();
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (server!=null)
|
||||
server.stop();
|
||||
@@ -543,22 +532,6 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
|
||||
return realm;
|
||||
}
|
||||
|
||||
@TestExtension
|
||||
public static class ComputerListenerImpl extends ComputerListener {
|
||||
@Override
|
||||
public void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException {
|
||||
VirtualChannel ch = c.getChannel();
|
||||
if (ch instanceof Channel)
|
||||
TestEnvironment.get().testCase.addChannel((Channel)ch);
|
||||
}
|
||||
}
|
||||
|
||||
private void addChannel(Channel ch) {
|
||||
synchronized (channels) {
|
||||
channels.add(ch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the older default Maven, while still allowing specification of other bundled Mavens.
|
||||
*/
|
||||
|
||||
@@ -88,13 +88,10 @@ import hudson.model.TaskListener;
|
||||
import hudson.model.UpdateSite;
|
||||
import hudson.model.User;
|
||||
import hudson.model.View;
|
||||
import hudson.remoting.Channel;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import hudson.remoting.Which;
|
||||
import hudson.security.ACL;
|
||||
import hudson.security.AbstractPasswordBasedSecurityRealm;
|
||||
import hudson.security.GroupDetails;
|
||||
import hudson.security.SecurityRealm;
|
||||
import hudson.security.csrf.CrumbIssuer;
|
||||
import hudson.slaves.CommandLauncher;
|
||||
import hudson.slaves.ComputerConnector;
|
||||
@@ -135,6 +132,7 @@ import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.jvnet.hudson.test.recipes.Recipe;
|
||||
import org.jvnet.hudson.test.rhino.JavaScriptDebugger;
|
||||
import org.kohsuke.stapler.ClassDescriptor;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
@@ -173,6 +171,7 @@ import java.lang.management.ThreadInfo;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
@@ -217,9 +216,9 @@ import static org.junit.matchers.JUnitMatchers.containsString;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
/**
|
||||
* JUnit 4.10+ style rule to allow test cases to fire up a Jenkins instance
|
||||
* JUnit rule to allow test cases to fire up a Jenkins instance.
|
||||
*
|
||||
* @see <a href="http://wiki.jenkins-ci.org/display/JENKINS/Unit+Test+JUnit4">Wiki article about unit testing in Jenkins</a>
|
||||
* @see <a href="http://wiki.jenkins-ci.org/display/JENKINS/Unit+Test">Wiki article about unit testing in Jenkins</a>
|
||||
* @author Stephen Connolly
|
||||
* @since 1.436
|
||||
*/
|
||||
@@ -229,8 +228,6 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
|
||||
private Description testDescription;
|
||||
|
||||
private static JenkinsRule CURRENT = null;
|
||||
|
||||
/**
|
||||
* Points to the same object as {@link #jenkins} does.
|
||||
*/
|
||||
@@ -250,7 +247,7 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
* <p>
|
||||
* Just like {@link javax.servlet.ServletContext#getContextPath()}, starts with '/' but doesn't end with '/'.
|
||||
*/
|
||||
protected String contextPath = "";
|
||||
protected String contextPath = "/jenkins";
|
||||
|
||||
/**
|
||||
* {@link Runnable}s to be invoked at {@link #after()} .
|
||||
@@ -264,11 +261,6 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
*/
|
||||
private List<WebClient> clients = new ArrayList<WebClient>();
|
||||
|
||||
/**
|
||||
* Remember channels that are created, to release them at the end.
|
||||
*/
|
||||
private List<Channel> channels = new ArrayList<Channel>();
|
||||
|
||||
/**
|
||||
* JavaScript "debugger" that provides you information about the JavaScript call stack
|
||||
* and the current values of the local variables in those stack frame.
|
||||
@@ -392,8 +384,11 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
/**
|
||||
* Override to tear down your specific external resource.
|
||||
*/
|
||||
protected void after() {
|
||||
protected void after() throws Exception {
|
||||
try {
|
||||
for (EndOfTestListener tl : jenkins.getExtensionList(EndOfTestListener.class))
|
||||
tl.onTearDown();
|
||||
|
||||
if (timeoutTimer!=null) {
|
||||
timeoutTimer.cancel();
|
||||
timeoutTimer = null;
|
||||
@@ -411,20 +406,6 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
}
|
||||
clients.clear();
|
||||
|
||||
for (Channel c : channels)
|
||||
try {
|
||||
c.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
for (Channel c : channels)
|
||||
try {
|
||||
c.join();
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
channels.clear();
|
||||
|
||||
} finally {
|
||||
try {
|
||||
server.stop();
|
||||
@@ -476,7 +457,6 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
Thread t = Thread.currentThread();
|
||||
String o = t.getName();
|
||||
t.setName("Executing "+ testDescription.getDisplayName());
|
||||
CURRENT = JenkinsRule.this;
|
||||
before();
|
||||
try {
|
||||
System.out.println("=== Starting " + testDescription.getDisplayName());
|
||||
@@ -503,7 +483,6 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
after();
|
||||
testDescription = null;
|
||||
t.setName(o);
|
||||
CURRENT = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -615,16 +594,6 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
return realm;
|
||||
}
|
||||
|
||||
@TestExtension
|
||||
public static class ComputerListenerImpl extends ComputerListener {
|
||||
@Override
|
||||
public void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException {
|
||||
VirtualChannel ch = c.getChannel();
|
||||
if (ch instanceof Channel)
|
||||
CURRENT.channels.add((Channel)ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the older default Maven, while still allowing specification of other bundled Mavens.
|
||||
@@ -1033,7 +1002,7 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
}
|
||||
|
||||
public <N extends Node> N configRoundtrip(N node) throws Exception {
|
||||
submit(createWebClient().goTo("/computer/" + node.getNodeName() + "/configure").getFormByName("config"));
|
||||
submit(createWebClient().goTo("computer/" + node.getNodeName() + "/configure").getFormByName("config"));
|
||||
return (N)jenkins.getNode(node.getNodeName());
|
||||
}
|
||||
|
||||
@@ -1767,7 +1736,7 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
* Logs in to Hudson.
|
||||
*/
|
||||
public WebClient login(String username, String password) throws Exception {
|
||||
HtmlPage page = goTo("/login");
|
||||
HtmlPage page = goTo("login");
|
||||
// page = (HtmlPage) page.getFirstAnchorByText("Login").click();
|
||||
|
||||
HtmlForm form = page.getFormByName("login");
|
||||
@@ -1913,6 +1882,7 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
}
|
||||
|
||||
public Page goTo(String relative, String expectedContentType) throws IOException, SAXException {
|
||||
assert !relative.startsWith("/");
|
||||
Page p = super.getPage(getContextPath() + relative);
|
||||
assertThat(p.getWebResponse().getContentType(), is(expectedContentType));
|
||||
return p;
|
||||
@@ -1940,6 +1910,7 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
|
||||
* @since 1.504
|
||||
*/
|
||||
public void assertFails(String url, int statusCode) throws Exception {
|
||||
assert !url.startsWith("/");
|
||||
try {
|
||||
fail(url + " should have been rejected but produced: " + super.getPage(getContextPath() + url).getWebResponse().getContentAsString());
|
||||
} catch (FailingHttpStatusCodeException x) {
|
||||
|
||||
@@ -42,6 +42,9 @@ public class TestEnvironment {
|
||||
*/
|
||||
public final @CheckForNull HudsonTestCase testCase;
|
||||
|
||||
/**
|
||||
* Current test case being run (null for a JUnit 3 test).
|
||||
*/
|
||||
private final @CheckForNull Description description;
|
||||
|
||||
public final TemporaryDirectoryAllocator temporaryDirectoryAllocator = new TemporaryDirectoryAllocator();
|
||||
|
||||
@@ -113,12 +113,22 @@ public class TestPluginManager extends PluginManager {
|
||||
return names;
|
||||
}
|
||||
|
||||
// Overwrite PluginManager#stop, not to release plugins in each tests.
|
||||
// Releasing plugins result fail to access files in webapp directory in following tests.
|
||||
@Override
|
||||
public void stop() {
|
||||
for (PluginWrapper p : activePlugins)
|
||||
p.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* As we don't actually shut down classloaders, we instead provide this method that does
|
||||
* what {@link #stop()} normally does.
|
||||
*/
|
||||
private void reallyStop() {
|
||||
super.stop();
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TestPluginManager.class.getName());
|
||||
|
||||
static {
|
||||
@@ -126,6 +136,12 @@ public class TestPluginManager extends PluginManager {
|
||||
INSTANCE = new TestPluginManager();
|
||||
Runtime.getRuntime().addShutdownHook(new Thread("delete " + INSTANCE.rootDir) {
|
||||
@Override public void run() {
|
||||
// Shutdown and release plugins as in PluginManager#stop
|
||||
((TestPluginManager)INSTANCE).reallyStop();
|
||||
|
||||
// allow JVM cleanup handles of jar files...
|
||||
System.gc();
|
||||
|
||||
try {
|
||||
Util.deleteRecursive(INSTANCE.rootDir);
|
||||
} catch (IOException x) {
|
||||
|
||||
Reference in new issue
Block a user