Skip to content

Commit

Permalink
Triggers should be started on job creation
Browse files Browse the repository at this point in the history
[FIXES JENKINS-42446]
  • Loading branch information
scoheb committed Mar 9, 2017
1 parent 08a7978 commit 47622a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Expand Up @@ -196,6 +196,8 @@ public void setDefinition(FlowDefinition definition) {
} else {
quietPeriod = null;
}
getTriggersJobProperty().stopTriggers();
getTriggersJobProperty().startTriggers(Items.currentlyUpdatingByXml());
}


Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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);
Expand Down

0 comments on commit 47622a0

Please sign in to comment.