Skip to content
Permalink
Browse files

[JENKINS-26399] JenkinsRuleExt.waitForCompletion/Message

Originally-Committed-As: fac5ce62db53f18cabb2347f0bb6ae9e3f3ea1f9
  • Loading branch information
jglick committed Mar 18, 2015
1 parent 97f1280 commit eeeb0b13a82f05d688ea20d804ec65577587a9fb
@@ -86,6 +86,7 @@ public void assertThatWorkflowIsSuspended(WorkflowRun b, CpsFlowExecution e) thr
assert b.isBuilding();
}

/** @deprecated use {@link JenkinsRuleExt#waitForCompletion} instead */
public void waitForWorkflowToComplete() throws Exception {
do {
waitForWorkflowToSuspend(e);
@@ -327,10 +327,7 @@ private void startJnlpProc() throws Exception {
while (f2.isFile()) {
Thread.sleep(100);
}
while (b.isBuilding()) {
Thread.sleep(100);
}
assertBuildCompletedSuccessfully();
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertLogContains("finished waiting", b);
story.j.assertLogContains("OK, done", b);
killJnlpProc();
@@ -380,10 +377,7 @@ private void startJnlpProc() throws Exception {
while (f2.isFile()) {
Thread.sleep(100);
}
while (b.isBuilding()) {
Thread.sleep(100);
}
assertBuildCompletedSuccessfully();
story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b));
story.j.assertLogContains("finished waiting", b);
story.j.assertLogContains("OK, done", b);
killJnlpProc();
@@ -541,27 +535,21 @@ private void startJnlpProc() throws Exception {
startBuilding();
waitForWorkflowToSuspend();
assertTrue(b.isBuilding());
Thread.sleep(1500); // TODO how else to ensure that WorkflowRun.waitForCompletion has called copyLogs? (it flushes logs when a step finishes but cannot tell when start() returns, and it cannot listen for LogAction being added or written)
story.j.assertLogContains("running as someone", b);
JenkinsRuleExt.waitForMessage("running as someone", b);
CheckAuth.finish(false);
waitForWorkflowToSuspend();
assertTrue(b.isBuilding());
Thread.sleep(1500); // TODO
story.j.assertLogContains("still running as someone", b);
JenkinsRuleExt.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();
Thread.sleep(1500); // TODO
story.j.assertLogContains("again running as someone", b);
JenkinsRuleExt.waitForMessage("again running as someone", b);
CheckAuth.finish(true);
waitForWorkflowToComplete();
Thread.sleep(1500); // TODO
assertBuildCompletedSuccessfully();
story.j.assertLogContains("finally running as someone", b);
story.j.assertLogContains("finally running as someone", story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b)));
}
});
}
@@ -656,20 +644,14 @@ public static void finish(final boolean terminate) {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition("node('special') {echo 'OK ran'}"));
startBuilding();
while (!JenkinsRule.getLog(b).contains("Still waiting to schedule task")) {
Thread.sleep(100);
}
JenkinsRuleExt.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);
while (b.isBuilding()) {
Thread.sleep(100);
}
assertBuildCompletedSuccessfully();
story.j.assertLogContains("OK ran", b);
story.j.assertLogContains("OK ran", story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b)));
}
});
}
@@ -26,17 +26,21 @@

import hudson.Functions;
import java.io.File;
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;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.Rule;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.RestartableJenkinsRule;

public class PushdStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();

private String pwdStep() {
@@ -66,10 +70,7 @@ private String pwdStep() {
@Override public void evaluate() throws Throwable {
SemaphoreStep.success("restarting/1", null);
WorkflowRun b = story.j.jenkins.getItemByFullName("p", WorkflowJob.class).getLastBuild();
while (b.isBuilding()) { // TODO JENKINS-26399
Thread.sleep(100);
}
story.j.assertLogContains(File.separator + "subdir", story.j.assertBuildStatusSuccess(b));
story.j.assertLogContains(File.separator + "subdir", story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b)));
}
});
}

0 comments on commit eeeb0b1

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