Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ProcessHandle.destroy to implement RealJenkinsRule.stopJenkins #544

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.recipes.LocalData;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
Expand Down Expand Up @@ -757,17 +756,14 @@ public void stopJenkins() throws Throwable {
if (proc != null) {
Process _proc = proc;
proc = null;
endpoint("exit").openStream().close();
// Do not use Process.destroy as it closes streams, losing any final output:
_proc.toHandle().destroy();

if (!_proc.waitFor(60, TimeUnit.SECONDS) ) {
System.err.println("Jenkins failed to stop within 60 seconds, attempting to kill the Jenkins process");
_proc.destroyForcibly();
throw new AssertionError("Jenkins failed to terminate within 60 seconds");
}
int exitValue = _proc.exitValue();
if (exitValue != 0) {
throw new AssertionError("nonzero exit code: " + exitValue);
}
}
}

Expand Down Expand Up @@ -961,12 +957,6 @@ public void doStep(StaplerRequest req, StaplerResponse rsp) throws Throwable {
// TODO use raw err if it seems safe enough
Init2.writeSer(rsp.getOutputStream(), new OutputPayload(object, err != null ? new ProxyException(err) : null));
}
public HttpResponse doExit(@QueryParameter String token) throws IOException {
checkToken(token);
try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
return Jenkins.get().doSafeExit(null);
}
}
}

public static final class CustomJenkinsRule extends JenkinsRule implements AutoCloseable {
Expand Down