Skip to content
Permalink
Browse files

Triggers should be started on job creation

[FIXES JENKINS-42446]
  • Loading branch information
scoheb committed Mar 9, 2017
1 parent 08a7978 commit 47622a022bc226e7d4223053334912056803f081
@@ -196,6 +196,8 @@ public void setDefinition(FlowDefinition definition) {
} else {
quietPeriod = null;
}
getTriggersJobProperty().stopTriggers();
getTriggersJobProperty().startTriggers(Items.currentlyUpdatingByXml());
}


@@ -38,6 +38,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

@@ -93,10 +94,10 @@ public void submitCallsStartTrue() throws Exception {
t = (MockTrigger) p.getTriggers().get(t.getDescriptor());
assertNotNull(t);
// The first "null, false" is due to the p.addTrigger(t) call and won't apply in the real world.
assertEquals("[null, false, null, true]", MockTrigger.startsAndStops.toString());
assertEquals("[null, false, null, true, null, false]", MockTrigger.startsAndStops.toString());
Boolean currentStatus = t.currentStatus();
assertNotNull(currentStatus);
assertTrue(currentStatus);
assertFalse(currentStatus);
}

@Test
@@ -167,7 +168,7 @@ public void configRoundTrip() throws Exception {
assertNotNull(((MockTrigger)modTriggers.get(0)).currentStatus());

// The first "null, false" is due to the p.addTrigger(t) call and won't apply in the real world.
assertEquals("[null, false, null, true]", MockTrigger.startsAndStops.toString());
assertEquals("[null, false, null, true, null, false]", MockTrigger.startsAndStops.toString());
}

@Test
@@ -176,6 +177,16 @@ public void triggerPresentDuringStart() throws Exception {
r.configRoundtrip(p);
assertNull(getTriggerFromList(QueryingMockTrigger.class,
p.getTriggersJobProperty().getTriggers()));
configSubmit(p);

QueryingMockTrigger t = getTriggerFromList(QueryingMockTrigger.class,
p.getTriggersJobProperty().getTriggers());
assertNotNull(t);
assertTrue(t.isStarted);
assertTrue(t.foundSelf);
}

private void configSubmit(WorkflowJob p) throws Exception {
JenkinsRule.WebClient wc = r.createWebClient();
String newConfig = org.apache.commons.io.IOUtils.toString(
PipelineTriggersJobPropertyTest.class.getResourceAsStream(
@@ -187,6 +198,18 @@ public void triggerPresentDuringStart() throws Exception {
params.add(new NameValuePair("json", newConfig));
request.setRequestParameters(params);
wc.getPage(request);
}

@Issue("JENKINS-42446")
@Test
public void triggerPresentAndStartedDuringCreate() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "triggerPresent");
// configRoundTrip NOT called here since we want to mimic
// a job creation operation.
assertNull(getTriggerFromList(QueryingMockTrigger.class,
p.getTriggersJobProperty().getTriggers()));
configSubmit(p);

QueryingMockTrigger t = getTriggerFromList(QueryingMockTrigger.class,
p.getTriggersJobProperty().getTriggers());
assertNotNull(t);

0 comments on commit 47622a0

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