Skip to content

Commit

Permalink
[JENKINS-73835] Delete `LockStepTest.deleteRunningBuildNewBuildClears…
Browse files Browse the repository at this point in the history
…Lock` now that running builds may not be deleted (#716)

* [JENKINS-73835] Adjust LockStepTest.killThenDeleteRunningBuildNewBuildClearsLock now that running builds may not be deleted

* [JENKINS-73835] Just delete test instead, LockStepHardKillTest already covers WorkflowRun.doKill

* Format with spotless

---------

Co-authored-by: Mark Waite <[email protected]>
  • Loading branch information
dwnusbaum and MarkEWaite authored Oct 15, 2024
1 parent f310d75 commit 1f0dff5
Showing 1 changed file with 0 additions and 57 deletions.
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

0 comments on commit 1f0dff5

Please sign in to comment.