提交 1a80973a 编写于 作者: J Jesse Glick

Merge branch 'master' into FlyweightTask-JENKINS-10944

......@@ -55,7 +55,9 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
FutureImpl does not cancel its start future.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-25514">issue 25514</a>)
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -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);
}
......
......@@ -63,7 +63,7 @@ public class ComputerRetentionWork extends PeriodicWork {
if (!nextCheck.containsKey(c) || startRun > nextCheck.get(c)) {
// at the moment I don't trust strategies to wait more than 60 minutes
// strategies need to wait at least one minute
final long waitInMins = Math.min(1, Math.max(60, c.getRetentionStrategy().check(c)));
final long waitInMins = Math.max(1, Math.min(60, c.getRetentionStrategy().check(c)));
nextCheck.put(c, startRun + waitInMins*1000*60 /*MINS->MILLIS*/);
}
}
......
......@@ -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;
......@@ -612,4 +613,33 @@ public class QueueTest {
} catch (CancellationException e) {
}
}
@Test public void waitForStartAndCancelBeforeStart() throws Exception {
final OneShotEvent ev = new OneShotEvent();
FreeStyleProject p = r.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) {}
}
}
......@@ -25,27 +25,36 @@ package lib.form;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import net.sf.json.JSONObject;
import org.jvnet.hudson.test.HudsonTestCase;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.StaplerRequest;
/**
* Tests the handling of @nameRef in the form tree.
*
* @author Kohsuke Kawaguchi
*/
public class NameRefTest extends HudsonTestCase {
public void test1() throws Exception {
jenkins.setCrumbIssuer(null);
HtmlPage p = createWebClient().goTo("self/test1");
submit(p.getFormByName("config"));
public class NameRefTest {
@Rule public JenkinsRule r = new JenkinsRuleWithJelly();
@Test public void test() throws Exception {
r.jenkins.setCrumbIssuer(null);
HtmlPage p = r.createWebClient().goTo("self/test1");
r.submit(p.getFormByName("config"));
}
public HttpResponse doSubmitTest1(StaplerRequest req) throws Exception {
JSONObject f = req.getSubmittedForm();
System.out.println(f);
assertEquals("{\"foo\":{\"bar\":{\"zot\":\"zot\"}}}",f.toString());
return HttpResponses.ok();
public static class JenkinsRuleWithJelly extends JenkinsRule {
public HttpResponse doSubmitTest1(StaplerRequest req) throws Exception {
JSONObject f = req.getSubmittedForm();
System.out.println(f);
assertEquals("{\"foo\":{\"bar\":{\"zot\":\"zot\"}}}",f.toString());
return HttpResponses.ok();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册