Skip to content
Permalink
Browse files

[JENKINS-25514] Fixed lock case in FutureImpl

when some other process is waiting for build in queue.
  • Loading branch information
jbaranov committed Nov 30, 2014
1 parent 6bf6e7f commit 3edae667b3955a561296a23122f86b35ec928a98
@@ -84,6 +84,14 @@ public boolean cancel(boolean mayInterruptIfRunning) {
}
}

@Override
public synchronized void setAsCancelled() {
super.setAsCancelled();
if (!start.isDone()) {
start.setAsCancelled();
}
}

synchronized void addExecutor(@Nonnull Executor executor) {
this.executors.add(executor);
}
@@ -62,6 +62,7 @@
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
@@ -579,4 +580,33 @@ public void testCancelInQueue() throws Exception
} catch (CancellationException e) {
}
}

public void testWaitForStartAndCancelBeforeStart() throws Exception {
final OneShotEvent ev = new OneShotEvent();
FreeStyleProject p = createFreeStyleProject();

QueueTaskFuture<FreeStyleBuild> f = p.scheduleBuild2(10);
final Queue.Item item = Queue.getInstance().getItem(p);
assertNotNull(item);

final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
executor.schedule(new Runnable() {
@Override
public void run() {
try {
Queue.getInstance().doCancelItem(item.id);
} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
}
}, 2, TimeUnit.SECONDS);

try {
f.waitForStart();
fail("Expected an CancellationException to be thrown");
} catch (CancellationException e) {}
}

}

0 comments on commit 3edae66

Please sign in to comment.
You can’t perform that action at this time.