提交 3a2def79 编写于 作者: K Kohsuke Kawaguchi

CLI connection needs to be shut down at the end of the test to release resources

上级 a1003269
......@@ -121,6 +121,9 @@ public class CLI {
return Integer.parseInt(p);
}
/**
* Shuts down the channel and closes the underlying connection.
*/
public void close() throws IOException, InterruptedException {
channel.close();
channel.join();
......
......@@ -54,10 +54,16 @@ public class BuildCommandTest extends HudsonTestCase {
}] as TestBuilder);
// this should be asynchronous
assertEquals(0,new CLI(getURL()).execute(["build", p.name]))
started.block();
assertTrue(p.getBuildByNumber(1).isBuilding())
completed.signal();
def cli = new CLI(getURL())
try {
assertEquals(0,cli.execute(["build", p.name]))
started.block()
assertTrue(p.getBuildByNumber(1).isBuilding())
completed.signal()
} finally {
cli.close();
}
}
/**
......@@ -67,16 +73,28 @@ public class BuildCommandTest extends HudsonTestCase {
def p = createFreeStyleProject();
p.buildersList.add(new Shell("sleep 3"));
new CLI(getURL()).execute(["build","-s",p.name])
assertFalse(p.getBuildByNumber(1).isBuilding())
def cli = new CLI(getURL())
try {
cli.execute(["build","-s",p.name])
assertFalse(p.getBuildByNumber(1).isBuilding())
} finally {
cli.close();
}
}
void testParameters() {
def p = createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty([new StringParameterDefinition("key",null)]));
new CLI(getURL()).execute(["build","-s","-p","key=foobar",p.name]);
def b = assertBuildStatusSuccess(p.getBuildByNumber(1));
assertEquals("foobar",b.getAction(ParametersAction.class).getParameter("key").value);
def cli = new CLI(getURL())
try {
cli.execute(["build","-s","-p","key=foobar",p.name])
def b = assertBuildStatusSuccess(p.getBuildByNumber(1))
assertEquals("foobar",b.getAction(ParametersAction.class).getParameter("key").value)
} finally {
cli.close();
};
}
}
\ No newline at end of file
......@@ -36,10 +36,14 @@ public class EnableJobCommandTest extends HudsonTestCase {
def cli = new CLI(getURL())
cli.execute(["disable-job",p.name])
assertTrue(p.disabled)
cli.execute(["enable-job",p.name])
assertFalse(p.disabled)
try {
cli.execute(["disable-job",p.name])
assertTrue(p.disabled)
cli.execute(["enable-job",p.name])
assertFalse(p.disabled)
} finally {
cli.close();
}
}
}
\ No newline at end of file
......@@ -56,12 +56,17 @@ public class ItemListenerTest extends HudsonTestCase {
public void testOnCreatedViaCLI() throws Exception {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
PrintStream out = new PrintStream(buf);
new CLI(getURL()).execute(Arrays.asList("create-job","testJob"),
new ByteArrayInputStream(("<project><actions/><builders/><publishers/>"
+ "<buildWrappers/></project>").getBytes()),
out, out);
out.flush();
assertNotNull("job should be created: " + buf, hudson.getItem("testJob"));
assertEquals("onCreated event should be triggered: " + buf, "C", events.toString());
CLI cli = new CLI(getURL());
try {
cli.execute(Arrays.asList("create-job", "testJob"),
new ByteArrayInputStream(("<project><actions/><builders/><publishers/>"
+ "<buildWrappers/></project>").getBytes()),
out, out);
out.flush();
assertNotNull("job should be created: " + buf, hudson.getItem("testJob"));
assertEquals("onCreated event should be triggered: " + buf, "C", events.toString());
} finally {
cli.close();
}
}
}
......@@ -28,7 +28,12 @@ public class CliAuthenticationTest extends HudsonTestCase {
}
private int command(String... args) throws Exception {
return new CLI(getURL()).execute(args);
CLI cli = new CLI(getURL());
try {
return cli.execute(args);
} finally {
cli.close();
}
}
@TestExtension
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册