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 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</pluginRepositories>
<properties>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.479</jenkins.version>
<jenkins.version>2.480</jenkins.version>
Copy link
Member Author

@dwnusbaum dwnusbaum Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this PR just adds a test, I am not sure if we actually want to merge this as-is, or would prefer to wait for JENKINS-73824 to possibly get backported to 2.479.x.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK, it is an lts-candidate.

<no-test-jar>false</no-test-jar>
<useBeta>true</useBeta>
<hpi.compatibleSinceVersion>2.26</hpi.compatibleSinceVersion>
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
}

}