Skip to content
Permalink
Browse files

Merge pull request #146 from jglick/standard-test-utils-JENKINS-26399

[JENKINS-26399] Standard test utils
  • Loading branch information
jglick committed Jul 20, 2015
2 parents d5f5355 + 4b528c5 commit 2f6a9d24d2c8432e9b0abf6a31e00067fafd7ae0
Showing with 60 additions and 255 deletions.
  1. +0 −159 aggregator/src/test/java/org/jenkinsci/plugins/workflow/BuildWatcher.java
  2. +0 −27 aggregator/src/test/java/org/jenkinsci/plugins/workflow/JenkinsRuleExt.java
  3. +1 −0 aggregator/src/test/java/org/jenkinsci/plugins/workflow/SingleJobTestBase.java
  4. +2 −1 aggregator/src/test/java/org/jenkinsci/plugins/workflow/WorkflowRunTest.java
  5. +14 −14 aggregator/src/test/java/org/jenkinsci/plugins/workflow/WorkflowTest.java
  6. +1 −1 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreStepTest.java
  7. +2 −2 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java
  8. +3 −4 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/EnvStepTest.java
  9. +2 −3 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/PushdStepTest.java
  10. +2 −3 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/SleepStepTest.java
  11. +11 −13 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/StageTest.java
  12. +1 −1 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest.java
  13. +4 −5 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/WaitForConditionStepTest.java
  14. +3 −4 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/WorkspaceStepTest.java
  15. +4 −5 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/build/BuildTriggerStepRestartTest.java
  16. +6 −7 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/build/BuildTriggerStepTest.java
  17. +3 −4 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/build/RunWrapperTest.java
  18. +1 −2 aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/input/InputStepRestartTest.java

This file was deleted.

@@ -27,8 +27,6 @@
import hudson.EnvVars;
import hudson.model.Computer;
import hudson.model.Descriptor;
import hudson.model.Node.Mode;
import hudson.model.Run;
import hudson.model.Slave;
import hudson.slaves.CommandLauncher;
import hudson.slaves.NodeProperty;
@@ -47,31 +45,6 @@
*/
public class JenkinsRuleExt {

// TODO use standard version 1.607+

/**
* Waits for a build to complete.
* @return the same build, once done
*/
public static <R extends Run<?,?>> R waitForCompletion(R r) throws InterruptedException {
// Could be using com.jayway.awaitility:awaitility but it seems like overkill here.
while (r.isBuilding()) {
Thread.sleep(100);
}
return r;
}

/**
* Waits for a build log to contain a specified string.
* @return the same build, once it does
*/
public static <R extends Run<?,?>> R waitForMessage(String message, R r) throws IOException, InterruptedException {
while (!JenkinsRule.getLog(r).contains(message)) {
Thread.sleep(100);
}
return r;
}

/**
* Akin to {@link JenkinsRule#createSlave(String, String, EnvVars)} but allows {@link Computer#getEnvironment} to be controlled rather than directly modifying launchers.
* @param env variables to override in {@link Computer#getEnvironment}; null values will get unset even if defined in the test environment
@@ -34,6 +34,7 @@
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Rule;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RestartableJenkinsRule;

@@ -52,6 +52,7 @@
import org.junit.ClassRule;
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;
@@ -228,7 +229,7 @@ public void failedToStartRun() throws Exception {
assertNotNull(p);
WorkflowRun b = p.getLastBuild();
assertNotNull(b);
r.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
r.assertBuildStatusSuccess(r.waitForCompletion(b));
}

}
@@ -116,7 +116,7 @@ public void evaluate() throws Throwable {
}
liveness();
SemaphoreStep.success("wait/1", null);
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
}
});
}
@@ -162,7 +162,7 @@ private void liveness() {
rebuildContext(story.j);
assertThatWorkflowIsSuspended();
SemaphoreStep.success("wait/1", null);
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
}
});
}
@@ -198,7 +198,7 @@ private void liveness() {
rebuildContext(story.j);
assertThatWorkflowIsSuspended();
SemaphoreStep.success("wait/1", null);
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));

story.j.assertLogContains("before=demo", b);
story.j.assertLogContains("ONSLAVE=true", b);
@@ -232,7 +232,7 @@ private void liveness() {
@Override public void evaluate() throws Throwable {
rebuildContext(story.j);
SemaphoreStep.success("wait/1", null);
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
}
});
}
@@ -300,7 +300,7 @@ private void startJnlpProc() throws Exception {
while (f2.isFile()) {
Thread.sleep(100);
}
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
story.j.assertLogContains("finished waiting", b);
story.j.assertLogContains("OK, done", b);
killJnlpProc();
@@ -349,7 +349,7 @@ private void startJnlpProc() throws Exception {
while (f2.isFile()) {
Thread.sleep(100);
}
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
story.j.assertLogContains("finished waiting", b); // TODO sometimes is not printed to log, despite f2 having been removed
story.j.assertLogContains("OK, done", b);
killJnlpProc();
@@ -472,7 +472,7 @@ private void startJnlpProc() throws Exception {
SemaphoreStep.success("wait/2", null);
SemaphoreStep.success("wait/3", null);

story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
assertTrue(e.programPromise.get().closures.isEmpty());
}
});
@@ -490,21 +490,21 @@ private void startJnlpProc() throws Exception {
startBuilding();
waitForWorkflowToSuspend();
assertTrue(b.isBuilding());
JenkinsRuleExt.waitForMessage("running as someone", b);
story.j.waitForMessage("running as someone", b);
CheckAuth.finish(false);
waitForWorkflowToSuspend();
assertTrue(b.isBuilding());
JenkinsRuleExt.waitForMessage("still running as someone", b);
story.j.waitForMessage("still running as someone", b);
}
});
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
assertEquals(JenkinsRule.DummySecurityRealm.class, jenkins().getSecurityRealm().getClass());
rebuildContext(story.j);
assertThatWorkflowIsSuspended();
JenkinsRuleExt.waitForMessage("again running as someone", b);
story.j.waitForMessage("again running as someone", b);
CheckAuth.finish(true);
story.j.assertLogContains("finally running as someone", story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b)));
story.j.assertLogContains("finally running as someone", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
}
});
}
@@ -586,7 +586,7 @@ public static void finish(final boolean terminate) {
rebuildContext(story.j);
assertThatWorkflowIsSuspended();
SemaphoreStep.success("env/1", null);
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
story.j.assertLogContains("tag=jenkins-demo-1 PERMACHINE=set", b);
story.j.assertLogContains("tag2=custom", b);
story.j.assertLogContains("tag3=custom2 stuff=more", b);
@@ -608,15 +608,15 @@ public static void finish(final boolean terminate) {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition("node('special') {echo 'OK ran'}"));
startBuilding();
JenkinsRuleExt.waitForMessage("Still waiting to schedule task", b);
story.j.waitForMessage("Still waiting to schedule task", b);
}
});
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
story.j.createSlave("special", null);
rebuildContext(story.j);
// TODO JENKINS-27532 sometimes two copies of the WorkflowRun are loaded
story.j.assertLogContains("OK ran", story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b)));
story.j.assertLogContains("OK ran", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
}
});
}
@@ -30,14 +30,14 @@
import hudson.tasks.junit.TestResultAction;
import java.util.List;
import javax.mail.internet.InternetAddress;
import org.jenkinsci.plugins.workflow.BuildWatcher;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.ClassRule;
import org.junit.Rule;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.mock_javamail.Mailbox;

@@ -42,7 +42,6 @@
import java.util.Locale;
import java.util.Map;
import jenkins.tasks.SimpleBuildWrapper;
import org.jenkinsci.plugins.workflow.BuildWatcher;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
@@ -54,6 +53,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.RestartableJenkinsRule;
import org.jvnet.hudson.test.TestExtension;
@@ -83,7 +83,7 @@
SemaphoreStep.success("restarting/1", null);
WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getLastBuild();
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
String expected = "/home/jenkins/extra/bin:/usr/bin:/bin";
story.j.assertLogContains("groovy PATH=" + expected + ":", b);
story.j.assertLogContains("shell PATH=" + expected + ":", b);

0 comments on commit 2f6a9d2

Please sign in to comment.