-
-
Notifications
You must be signed in to change notification settings - Fork 107
Recover gracefully when a PlaceholderTask is in the queue but the associated build is complete
#185
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8db0ae1
Add ignored test where a PlaceholderTask is in the queue but the asso…
dwnusbaum d0632af
Update annotation to explain why test is ignored
dwnusbaum 3abef26
Simplify test using JenkinsSessionRule.getHome and TemporaryFolder
dwnusbaum 00cdd69
De-flake test and update to released version of jenkins-test-harness
dwnusbaum 9d8eeca
Check if build is complete in PlaceholderTask.getCauseOfBlockage and …
dwnusbaum e0b5abf
Simplify lambda in PlaceholderTask.getCauseOfBlockage
dwnusbaum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| import hudson.model.FreeStyleProject; | ||
| import hudson.model.Item; | ||
| import hudson.model.Job; | ||
| import hudson.model.Label; | ||
| import hudson.model.Node; | ||
| import hudson.model.Queue; | ||
| import hudson.model.Result; | ||
|
|
@@ -79,7 +80,9 @@ | |
|
|
||
| import hudson.util.VersionNumber; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.StandardCopyOption; | ||
| import java.util.Set; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import jenkins.model.Jenkins; | ||
| import jenkins.security.MasterToSlaveCallable; | ||
| import jenkins.security.QueueItemAuthenticator; | ||
|
|
@@ -126,6 +129,7 @@ | |
| import static org.junit.Assert.fail; | ||
| import org.junit.Assume; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Ignore; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
|
|
@@ -1264,6 +1268,44 @@ public void accessPermittedOnlyFromCurrentBuild() throws Throwable { | |
| r.buildAndAssertSuccess(main); | ||
| }); | ||
| } | ||
|
|
||
| @Ignore("TODO safe fix still TBD") | ||
| @Test public void placeholderTaskInQueueButAssociatedBuildComplete() throws Throwable { | ||
| AtomicReference<File> rootDir = new AtomicReference<>(); | ||
| Path tempQueueFile = Files.createTempFile("queue", ".xml"); | ||
| sessions.then(r -> { | ||
| rootDir.set(r.jenkins.getRootDir()); | ||
| System.out.println(rootDir); | ||
| WorkflowJob p = r.createProject(WorkflowJob.class, "p"); | ||
| p.setDefinition(new CpsFlowDefinition("node('custom-label') { }", true)); | ||
| WorkflowRun b = p.scheduleBuild2(0).waitForStart(); | ||
| // Get into a state where a PlaceholderTask is in the queue. | ||
| while (true) { | ||
| Queue.Item[] items = Queue.getInstance().getItems(); | ||
| if (items.length == 1 && items[0].task instanceof ExecutorStepExecution.PlaceholderTask) { | ||
| break; | ||
| } | ||
| Thread.sleep(500L); | ||
| } | ||
| // Copy queue.xml to a temp file while the PlaceholderTask is in the queue. | ||
| r.jenkins.getQueue().save(); | ||
| Files.copy(rootDir.get().toPath().resolve("queue.xml"), tempQueueFile, StandardCopyOption.REPLACE_EXISTING); | ||
| // Create a node with the correct label and let the build complete. | ||
| DumbSlave node = r.createOnlineSlave(Label.get("custom-label")); | ||
| r.assertBuildStatusSuccess(r.waitForCompletion(b)); | ||
| }); | ||
| // Copy the temp queue.xml over the real one. The associated build has already completed, so the queue now | ||
| // has a bogus PlaceholderTask. | ||
| Files.copy(tempQueueFile, rootDir.get().toPath().resolve("queue.xml"), StandardCopyOption.REPLACE_EXISTING); | ||
| sessions.then(r -> { | ||
| WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class); | ||
| WorkflowRun b = p.getBuildByNumber(1); | ||
| assertFalse(b.isLogUpdated()); | ||
| r.assertBuildStatusSuccess(b); | ||
| assertThat(Queue.getInstance().getItems(), emptyArray()); // This assertion fails. | ||
dwnusbaum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW the reason there was no newline here before is that this step was a |
||
| public static final class WriteBackStep extends Step { | ||
| static File controllerFile; | ||
| static boolean legal = true; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.