Skip to content

Commit

Permalink
Skip probing disabled Jobs.
Browse files Browse the repository at this point in the history
Includes minor updates to Polling tests. JENKINS-50634
  • Loading branch information
p4paul committed Apr 10, 2018
1 parent d330bbc commit 3d03754
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 64 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/jenkinsci/plugins/p4/trigger/P4Hook.java
Expand Up @@ -101,9 +101,12 @@ public void doChangeSubmit(StaplerRequest req, StaplerResponse rsp)

private void probeJobs(@CheckForNull String port, List<Job> jobs) throws IOException {
for (Job<?, ?> job : jobs) {
P4Trigger trigger = null;
if(!job.isBuildable()) {
continue;
}
LOGGER.fine("P4: trying: " + job.getName());

P4Trigger trigger = null;
if (job instanceof ParameterizedJobMixIn.ParameterizedJob) {
ParameterizedJobMixIn.ParameterizedJob pJob = (ParameterizedJobMixIn.ParameterizedJob) job;
for (Trigger<?> t : pJob.getTriggers().values()) {
Expand Down
27 changes: 26 additions & 1 deletion src/test/java/org/jenkinsci/plugins/p4/DefaultEnvironment.java
Expand Up @@ -17,6 +17,8 @@
import org.jvnet.hudson.test.JenkinsRule;

import java.io.IOException;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -76,7 +78,7 @@ protected void submitFile(JenkinsRule jenkins, String path, String content) thro
String stream = null;
String line = "LOCAL";
String view = path + " //" + client + "/" + filename;
WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, stream, line, view);
WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, stream, line, view, null, null, null, true);
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", true, client, spec);

// Populate with P4 scm
Expand Down Expand Up @@ -136,4 +138,27 @@ protected void commitFile(JenkinsRule jenkins, String path, String content) thro
FreeStyleBuild build = project.scheduleBuild2(0, cause).get();
assertEquals(Result.SUCCESS, build.getResult());
}

public class TestHandler extends Handler {

private StringBuffer sb = new StringBuffer();

@Override
public void publish(LogRecord record) {
sb.append(record.getMessage());
sb.append("\n");
}

@Override
public void flush() {
}

@Override
public void close() throws SecurityException {
}

public StringBuffer getLogBuffer() {
return sb;
}
}
}
84 changes: 22 additions & 62 deletions src/test/java/org/jenkinsci/plugins/p4/client/PollingTest.java
Expand Up @@ -38,9 +38,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -68,16 +66,14 @@ public void buildCredentials() throws Exception {
public void testPollingPin() throws Exception {

String client = "manual.ws";
String stream = null;
String line = "LOCAL";
String view = "//depot/... //" + client + "/...";
WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view);
WorkspaceSpec spec = new WorkspaceSpec(view, null);

FreeStyleProject project = jenkins.createFreeStyleProject("PollingPin");
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec);

// Pin at label auto15
Populate populate = new AutoCleanImpl(true, true, false, false, "auto15", null);
Populate populate = new AutoCleanImpl(true, true, false, false, false, "auto15", null);
PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate);
project.setScm(scm);
project.save();
Expand All @@ -104,16 +100,14 @@ public void testPollingPin() throws Exception {
public void testPollingInc() throws Exception {

String client = "manual.ws";
String stream = null;
String line = "LOCAL";
String view = "//depot/... //" + client + "/...";
WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view);
WorkspaceSpec spec = new WorkspaceSpec(view, null);

FreeStyleProject project = jenkins.createFreeStyleProject("PollingInc");
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec);

// Pin at label auto15
Populate populate = new AutoCleanImpl(true, true, false, false, "auto15", null);
Populate populate = new AutoCleanImpl(true, true, false,false, false, "auto15", null);
List<Filter> filter = new ArrayList<Filter>();
FilterPerChangeImpl inc = new FilterPerChangeImpl(true);
filter.add(inc);
Expand Down Expand Up @@ -147,15 +141,13 @@ public void testPollingInc() throws Exception {
public void testPollingMask() throws Exception {

String client = "manual.ws";
String stream = null;
String line = "LOCAL";
String view = "//depot/... //" + client + "/...";
WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view);
WorkspaceSpec spec = new WorkspaceSpec(view, null);

FreeStyleProject project = jenkins.createFreeStyleProject("PollingMask");
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec);

Populate populate = new AutoCleanImpl(true, true, false, false, null, null);
Populate populate = new AutoCleanImpl();
List<Filter> filter = new ArrayList<Filter>();

// Filter changes outside of //depot/Data path
Expand Down Expand Up @@ -189,15 +181,13 @@ public void testPollingMask() throws Exception {
public void testPollingMaskExcl() throws Exception {

String client = "manual.ws";
String stream = null;
String line = "LOCAL";
String view = "//depot/... //" + client + "/...";
WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view);
WorkspaceSpec spec = new WorkspaceSpec(view, null);

FreeStyleProject project = jenkins.createFreeStyleProject("PollingMaskExcl");
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec);

Populate populate = new AutoCleanImpl(true, true, false, false, null, null);
Populate populate = new AutoCleanImpl();
List<Filter> filter = new ArrayList<Filter>();

// Filter changes outside of //depot/Main and also under //depot/Main/TPI-83
Expand Down Expand Up @@ -237,15 +227,13 @@ public void testPollingMaskExcl() throws Exception {
public void testPatternList() throws Exception {

String client = "manual.ws";
String stream = null;
String line = "LOCAL";
String view = "//depot/... //" + client + "/...";
WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view);
WorkspaceSpec spec = new WorkspaceSpec(view, null);

FreeStyleProject project = jenkins.createFreeStyleProject("PatternList");
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec);

Populate populate = new AutoCleanImpl(true, true, false, false, null, null);
Populate populate = new AutoCleanImpl();
List<Filter> filter = new ArrayList<Filter>();

StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -297,15 +285,13 @@ public void testPatternList() throws Exception {
@Test
public void testPatternListCaseSensitive() throws Exception {
String client = "manual.ws";
String stream = null;
String line = "LOCAL";
String view = "//depot/... //" + client + "/...";
WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view);
WorkspaceSpec spec = new WorkspaceSpec(view, null);

FreeStyleProject project = jenkins.createFreeStyleProject("PatternListCaseSensitive");
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec);

Populate populate = new AutoCleanImpl(true, true, false, false, null, null);
Populate populate = new AutoCleanImpl();
List<Filter> filter = new ArrayList<Filter>();

// Only poll on a main with lower case 'm' (doesn't actually exist) -- ensure case sensitive is TRUE!
Expand Down Expand Up @@ -377,15 +363,13 @@ public void testPatternListPipeline() throws Exception {
public void testPatternListInvalidPattern() throws Exception {

String client = "manual.ws";
String stream = null;
String line = "LOCAL";
String view = "//depot/... //" + client + "/...";
WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view);
WorkspaceSpec spec = new WorkspaceSpec(view, null);

FreeStyleProject project = jenkins.createFreeStyleProject("PatternListInvalidPattern");
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec);

Populate populate = new AutoCleanImpl(true, true, false, false, null, null);
Populate populate = new AutoCleanImpl();
List<Filter> filter = new ArrayList<Filter>();

StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -441,7 +425,7 @@ public void testPatternListInvalidPattern() throws Exception {
public void shouldNotTriggerJobIfNoChange() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject("NotTriggerJobIfNoChange");
StaticWorkspaceImpl workspace = new StaticWorkspaceImpl("none", false, defaultClient());
Populate populate = new AutoCleanImpl(true, true, false, false, null, null);
Populate populate = new AutoCleanImpl();
PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate);
project.setScm(scm);
P4Trigger trigger = new P4Trigger();
Expand All @@ -464,14 +448,12 @@ public void shouldNotTriggerJobIfNoChange() throws Exception {
@Test
public void shouldTriggerJobIfChanges() throws Exception {
String client = "manual.ws";
String stream = null;
String line = "LOCAL";
String view = "//depot/... //" + client + "/...";
WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view);
WorkspaceSpec spec = new WorkspaceSpec(view, null);
FreeStyleProject project = jenkins.createFreeStyleProject("TriggerJobIfChanges");
ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec);
// Pin at label auto15
Populate populate = new AutoCleanImpl(true, true, false, false, null, null);
Populate populate = new AutoCleanImpl();
PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate);
project.setScm(scm);
P4Trigger trigger = new P4Trigger();
Expand Down Expand Up @@ -507,7 +489,7 @@ public void testShouldTriggerPipelineJobIfChanges() throws Exception {
+ "node {\n"
+ " p4sync credential: '" + CREDENTIAL + "',"
+ " depotPath: '//depot', format: 'test.ws'\n"
+ "}"));
+ "}", false));

// Set review to build change 9
List<ParameterValue> list = new ArrayList<ParameterValue>();
Expand Down Expand Up @@ -539,8 +521,10 @@ public void testShouldTriggerPipelineJobIfChanges() throws Exception {
public void testShouldNotTriggerPipelineIfNoChanges() throws Exception {

WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "NotTriggerPipelineIfNoChanges");
job.setDefinition(new CpsFlowDefinition(
"" + "node {\n" + " p4sync credential: '" + CREDENTIAL + "', template: 'test.ws'" + "\n" + "}"));
job.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " p4sync credential: '" + CREDENTIAL + "', template: 'test.ws'" + "\n"
+ "}", false));

// Add a trigger
P4Trigger trigger = new P4Trigger();
Expand All @@ -561,28 +545,4 @@ public void testShouldNotTriggerPipelineIfNoChanges() throws Exception {

assertEquals("Shouldn't have triggered a build as no changes", 1, job.getLastBuild().getNumber());
}


private class TestHandler extends Handler {

private StringBuffer sb = new StringBuffer();

@Override
public void publish(LogRecord record) {
sb.append(record.getMessage());
sb.append("\n");
}

@Override
public void flush() {
}

@Override
public void close() throws SecurityException {
}

public StringBuffer getLogBuffer() {
return sb;
}
}
}

0 comments on commit 3d03754

Please sign in to comment.