Skip to content
Permalink
Browse files

Merge pull request #1472 from jbaranov/JENKINS-25514

[JENKINS-25514] Fixed lock case in FutureImpl
  • Loading branch information
olivergondza committed Jan 6, 2015
2 parents 4470b9e + 3edae66 commit 5bfaca449ce3b6edbf39a3f623bc8ce62411b37e
@@ -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;
@@ -567,4 +568,33 @@ public String getDisplayName() {
} 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 5bfaca4

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