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

Honoring termination milestones #766

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO until in BOM -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>999999-SNAPSHOT</version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/301 -->
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,8 @@ public void pause(final boolean v) throws IOException {
}

@Restricted(DoNotUse.class)
@Terminator public static void suspendAll() {
@Terminator(attains = FlowExecutionList.EXECUTIONS_SUSPENDED)
public static void suspendAll() {
CpsFlowExecution exec = null;
try (Timeout t = Timeout.limit(3, TimeUnit.MINUTES)) { // TODO some complicated sequence of calls to Futures could allow all of them to run in parallel
LOGGER.fine("starting to suspend all executions");
Expand Down Expand Up @@ -2164,10 +2165,4 @@ private void checkAndAbortNonresumableBuild() {
}
}

/** Ensures that even if we're limiting persistence of data for performance, we still write out data for shutdown. */
@Override
protected void notifyShutdown() {
// No-op, handled in the suspendAll terminator
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import jenkins.model.Jenkins;
import org.apache.commons.io.FileUtils;
import org.hamcrest.Matchers;
import static org.hamcrest.Matchers.containsInRelativeOrder;
import org.htmlunit.ElementNotFoundException;
import org.htmlunit.FailingHttpStatusCodeException;
import org.htmlunit.HttpMethod;
Expand All @@ -66,6 +67,7 @@
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.jenkinsci.plugins.workflow.cps.GroovySourceFileAllowlist.DefaultAllowlist;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionList;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
Expand Down Expand Up @@ -622,4 +624,16 @@ public boolean isAllowed(String groovyResourceUrl) {
assertThat(EnvActionImpl.forRun(b).getEnvironment().get("foo"), equalTo("bar"));
});
}

@Test public void suspendOrder() throws Throwable {
System.setProperty(Jenkins.class.getName() + "." + "termLogLevel", "INFO");
logger.record(CpsFlowExecution.class, Level.FINE).record(FlowExecutionList.class, Level.FINE).capture(100);
sessions.then(r -> {
WorkflowJob p = r.createProject(WorkflowJob.class);
p.setDefinition(new CpsFlowDefinition("echo 'ok'", true));
r.buildAndAssertSuccess(p);
});
assertThat(logger.getMessages(), containsInRelativeOrder("finished suspending all executions", "ensuring all executions are saved"));
}

}