提交 5bfaca44 编写于 作者: O Oliver Gondža

Merge pull request #1472 from jbaranov/JENKINS-25514

[JENKINS-25514] Fixed lock case in FutureImpl
......@@ -84,6 +84,14 @@ public final class FutureImpl extends AsyncFutureImpl<Executable> implements Que
}
}
@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.List;
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;
......@@ -567,4 +568,33 @@ public class QueueTest {
} 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) {}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册