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

[JENKINS-73824] Add test for deleting a Pipeline job while one of its builds is running only on a OneOffExecutor #468

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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: 11 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
</pluginRepositories>
<properties>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.479</jenkins.version>
<!-- TODO: Waiting for https://github.com/jenkinsci/workflow-job-plugin/pull/468 to make it to an LTS line. -->
dwnusbaum marked this conversation as resolved.
Show resolved Hide resolved
<jenkins.version>2.479-rc35394.6ec50c7e34f9</jenkins.version>
<no-test-jar>false</no-test-jar>
<useBeta>true</useBeta>
<hpi.compatibleSinceVersion>2.26</hpi.compatibleSinceVersion>
Expand All @@ -73,14 +74,21 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.462.x</artifactId>
<version>3221.ve8f7b_fdd149d</version>
<artifactId>bom-weekly</artifactId>
dwnusbaum marked this conversation as resolved.
Show resolved Hide resolved
<version>3387.v0f2773fa_3200</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<!-- Waiting for a release of https://github.com/jenkinsci/plugin-pom/pull/1004 -->
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
basil marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>ionicons-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jenkinsci.plugins.workflow.job;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand All @@ -12,20 +14,30 @@
import org.htmlunit.html.HtmlCheckBoxInput;
import org.htmlunit.html.HtmlForm;
import hudson.cli.CLICommandInvoker;
import hudson.model.Executor;
import hudson.model.Result;
import hudson.plugins.git.GitSCM;
import hudson.security.WhoAmI;
import hudson.triggers.SCMTrigger;
import java.util.Objects;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jenkins.plugins.git.GitSampleRepoRule;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RunLoadCounter;

public class WorkflowJobTest {
private static final Logger LOGGER = Logger.getLogger(WorkflowJobTest.class.getName());

@ClassRule public static BuildWatcher watcher = new BuildWatcher();

@Rule public JenkinsRule j = new JenkinsRule();
@Rule public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();
Expand Down Expand Up @@ -157,4 +169,35 @@ public void newBuildsShouldNotLoadOld() throws Throwable {
});
}

@Issue("JENKINS-73824")
@Test
dwnusbaum marked this conversation as resolved.
Show resolved Hide resolved
public void deletionShouldWaitForBuildsToComplete() throws Throwable {
var p = j.createProject(WorkflowJob.class);
p.setDefinition(new CpsFlowDefinition(
"""
try {
echo 'about to sleep'
sleep 999
} catch(e) {
echo 'aborting soon'
sleep 3
}
""", true));
var b = p.scheduleBuild2(0).waitForStart();
j.waitForMessage("about to sleep", b);
// The build isn't done and catches the interruption, so ItemDeletion.cancelBuildsInProgress should have to wait at least 3 seconds for it to complete.
LOGGER.info(() -> "Deleting " + p);
p.delete();
LOGGER.info(() -> "Deleted " + p);
// Make sure that the job really has been deleted.
assertThat(j.jenkins.getItemByFullName(p.getFullName()), nullValue());
// ItemDeletion.cancelBuildsInProgress should guarantee that the queue is empty at this point.
var executables = Stream.of(j.jenkins.getComputers())
.flatMap(c -> c.getAllExecutors().stream())
.map(Executor::getCurrentExecutable)
.filter(Objects::nonNull)
.collect(Collectors.toList());
assertThat(executables, empty());
dwnusbaum marked this conversation as resolved.
Show resolved Hide resolved
}

}