Skip to content

Commit

Permalink
[JENKINS-21932] Merge pull request #1160
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Apr 13, 2014
2 parents eb0bfa5 + 0c3d670 commit fce4fed
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -86,6 +86,9 @@
<li class=rfe>
Suppress fingerprint link if fingerprint record isn't available.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-21818">issue 21818</a>)
<li class=bug>
Job hangs if one of multiple triggered builds was aborted
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-21932">issue 21932</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Queue.java
Expand Up @@ -646,7 +646,7 @@ public synchronized boolean cancel(Task p) {

public synchronized boolean cancel(Item item) {
LOGGER.log(Level.FINE, "Cancelling {0} item#{1}", new Object[] {item.task, item.id});
boolean r = item.leave(this);
boolean r = item.cancel(this);

LeftItem li = new LeftItem(item);
li.enter(this);
Expand Down
31 changes: 31 additions & 0 deletions test/src/test/java/hudson/model/QueueTest.java
Expand Up @@ -59,6 +59,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -548,4 +549,34 @@ public String getDisplayName() {
assertFalse("Project " + project2.getDisplayName() + " stuck in pendings",item.task.getName().equals(project2.getName()));
}
}

public void testCancelInQueue() throws Exception
{
// parepare an offline slave.
DumbSlave slave = createOnlineSlave();
assertFalse(slave.toComputer().isOffline());
slave.toComputer().disconnect(null).get();
assertTrue(slave.toComputer().isOffline());

FreeStyleProject p = createFreeStyleProject();
p.setAssignedNode(slave);

QueueTaskFuture<FreeStyleBuild> f = p.scheduleBuild2(0);
try {
f.get(3, TimeUnit.SECONDS);
fail("Should time out (as the slave is offline).");
} catch (TimeoutException e) {
}

Queue.Item item = Queue.getInstance().getItem(p);
assertNotNull(item);
Queue.getInstance().doCancelItem(item.id);
assertNull(Queue.getInstance().getItem(p));

try {
f.get(10, TimeUnit.SECONDS);
fail("Should not get (as it is cancelled).");
} catch (CancellationException e) {
}
}
}

0 comments on commit fce4fed

Please sign in to comment.