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-73835] Delete LockStepTest.deleteRunningBuildNewBuildClearsLock now that running builds may not be deleted #716

Merged
merged 3 commits into from
Oct 15, 2024
Merged
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 @@ -4,10 +4,8 @@
import static org.hamcrest.Matchers.hasEntry;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assume.assumeFalse;

import com.google.common.collect.ImmutableMap;
import hudson.Functions;
import hudson.model.Result;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -684,61 +682,6 @@ public void parallelLock() throws Exception {
assertNull(LockableResourcesManager.get().fromName("resource1"));
}

/* TODO: This test does not run on Windows. Before wasting another afternoon trying to fix this, I'd suggest watching
* a good movie instead. If you really want to try your luck, here are some pointers:
* - Windows doesn't like to delete files that are currently in use
* - When deleting a running pipeline job, the listener keeps its logfile open
* This has the potential to fail at two points:
* - Right when deleting the run: Jenkins tries to remove the run directory, which contains the open log file
* - After the test, on cleanup, the jenkins test harness tries to remove the complete Jenkins data directory
* Things already tried: Getting a handle on the listener and closing its logfile.
* Stupid idea: Implement a JEP-210 extension, which keeps log files in memory...
*/
@Issue("JENKINS-36479")
@Test
public void deleteRunningBuildNewBuildClearsLock() throws Exception {
assumeFalse(Functions.isWindows());

LockableResourcesManager.get().createResource("resource1");

WorkflowJob p1 = j.jenkins.createProject(WorkflowJob.class, "p");
p1.setDefinition(new CpsFlowDefinition("lock('resource1') { echo 'locked!'; semaphore 'wait-inside' }", true));
WorkflowRun b1 = p1.scheduleBuild2(0).waitForStart();
j.waitForMessage("locked!", b1);
SemaphoreStep.waitForStart("wait-inside/1", b1);

WorkflowJob p2 = j.jenkins.createProject(WorkflowJob.class, "p2");
p2.setDefinition(new CpsFlowDefinition("lock('resource1') {\n" + " semaphore 'wait-inside'\n" + "}", true));
WorkflowRun b2 = p2.scheduleBuild2(0).waitForStart();
// Make sure that b2 is blocked on b1's lock.
j.waitForMessage("[resource1] is locked by build " + b1.getFullDisplayName(), b2);
isPaused(b2, 1, 1);

// Now b2 is still sitting waiting for a lock. Create b3 and launch it to verify order of
// unlock.
WorkflowJob p3 = j.jenkins.createProject(WorkflowJob.class, "p3");
p3.setDefinition(new CpsFlowDefinition("lock('resource1') {\n" + " semaphore 'wait-inside'\n" + "}", true));
WorkflowRun b3 = p3.scheduleBuild2(0).waitForStart();
j.waitForMessage("[resource1] is locked by build " + b1.getFullDisplayName(), b3);
isPaused(b3, 1, 1);

b1.delete();

// Verify that b2 gets the lock.
j.waitForMessage("Trying to acquire lock on [Resource: resource1]", b2);
SemaphoreStep.success("wait-inside/2", b2);
// Verify that b2 releases the lock and finishes successfully.
j.waitForMessage("Lock released on resource [Resource: resource1]", b2);
j.assertBuildStatusSuccess(j.waitForCompletion(b2));
isPaused(b2, 1, 0);

// Now b3 should get the lock and do its thing.
j.waitForMessage("Trying to acquire lock on [Resource: resource1]", b3);
SemaphoreStep.success("wait-inside/3", b3);
j.assertBuildStatusSuccess(j.waitForCompletion(b3));
isPaused(b3, 1, 0);
}

@Test
public void unlockButtonWithWaitingRuns() throws Exception {
LockableResourcesManager.get().createResource("resource1");
Expand Down