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-60507] Testing effects of job removal #364

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
} else {
LOGGER.warning(() -> "failed to cancel " + item + " in response to " + cause);
}
// TODO RunningTasks.remove(context) ?

Check warning on line 174 in src/main/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepExecution.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: RunningTasks.remove(context) ?
break;
} else {
LOGGER.log(FINE, "no match on {0} with {1} vs. {2}", new Object[] {item, task.context, context});
Expand Down Expand Up @@ -1223,7 +1224,12 @@
static void add(StepContext context) {
RunningTasks holder = ExtensionList.lookupSingleton(RunningTasks.class);
synchronized (holder) {
holder.runningTasks.putIfAbsent(context, new RunningTask());
RunningTask existing = holder.runningTasks.putIfAbsent(context, new RunningTask());
if (existing == null) {
LOGGER.fine(() -> "registered new RunningTask for " + context);
} else {
LOGGER.warning(() -> context + " already had a RunningTask");
}
}
}

Expand Down Expand Up @@ -1260,7 +1266,10 @@
static void remove(StepContext context) {
RunningTasks holder = ExtensionList.lookupSingleton(RunningTasks.class);
synchronized (holder) {
if (holder.runningTasks.remove(context) == null) {
if (holder.runningTasks.remove(context) != null) {

Check warning on line 1269 in src/main/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepExecution.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1269 is only partially covered, one branch is missing
LOGGER.fine(() -> "removed RunningTask for " + context);
Thread.dumpStack();//TODO

Check warning on line 1271 in src/main/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepExecution.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL:
} else {
LOGGER.fine(() -> "no RunningTask to remove associated with " + context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,25 @@ public void getOwnerTaskPermissions() throws Throwable {
});
}

@Issue("JENKINS-60507")
@Test public void recreateJob() throws Throwable {
Assume.assumeFalse(useWatching); // irrelevant here
sessions.then(r -> {
logging.record(ExecutorStepExecution.class, Level.FINE);
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node('nonexistent') {}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertTrue(Queue.getInstance().cancel(await().until(
() -> Stream.of(Queue.getInstance().getItems()).filter(i -> i.task instanceof ExecutorStepExecution.PlaceholderTask && i.task.getOwnerTask() == p).
findFirst().orElse(null), notNullValue())));
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
p.delete();
WorkflowJob p2 = r.createProject(WorkflowJob.class, "p");
p2.setDefinition(new CpsFlowDefinition("node {}", true));
r.buildAndAssertSuccess(p2);
});
}

private static class MainAuthenticator extends QueueItemAuthenticator {
@Override public Authentication authenticate(Queue.Task task) {
return task instanceof WorkflowJob ? User.getById("dev", true).impersonate() : null;
Expand Down