Skip to content
Open
Prev Previous commit
Next Next commit
Removed tests that were moved to RetryStepDelayTest
  • Loading branch information
krotte1 authored and JoaoPPinto committed Aug 24, 2021
commit c6ea76c942b67f6f653f55f7074e5b89c822b6cf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -227,86 +226,4 @@ public void shouldRetryAfterInnerTimeout() throws Exception {
r.assertLogContains("try 2", run);
}

@Test
public void retryTimeout() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"int i = 0;\n" +
"retry(count: 3, timeDelay: 10, unit: 'SECONDS', useRetryDelay: true) {\n" +
" println 'Trying!'\n" +
" if (i++ < 2) error('oops');\n" +
" println 'Done!'\n" +
"}\n" +
"println 'Over!'"
, true));

long before = System.currentTimeMillis();
QueueTaskFuture<WorkflowRun> f = p.scheduleBuild2(0);
long after = System.currentTimeMillis();
long difference = after - before;
long timeInSeconds = TimeUnit.MILLISECONDS.convert(difference, TimeUnit.SECONDS);
assertTrue(timeInSeconds > 20);
WorkflowRun b = r.assertBuildStatusSuccess(f);

String log = JenkinsRule.getLog(b);
r.assertLogNotContains("\tat ", b);

int idx = 0;
for (String msg : new String[] {
"Trying!",
"oops",
"Will try again",
"Retrying",
"Trying!",
"oops",
"Will try again",
"Retrying",
"Trying!",
"Done!",
"Over!",
}) {
idx = log.indexOf(msg, idx + 1);
assertTrue(msg + " not found", idx != -1);
}

idx = 0;
for (String msg : new String[] {
"[Pipeline] retry",
"[Pipeline] {",
"[Pipeline] }",
"[Pipeline] {",
"[Pipeline] }",
"[Pipeline] {",
"[Pipeline] }",
"[Pipeline] // retry",
}) {
idx = log.indexOf(msg, idx + 1);
assertTrue(msg + " not found", idx != -1);
}
}

@Test
public void stackTraceOnErrorWithTimeout() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(
new CpsFlowDefinition(
"def count = 0\n"
+ "retry(count: 2, timeDelay: 10, unit: 'SECONDS', useRetryDelay: true) {\n"
+ " count += 1\n"
+ " echo 'Try #' + count\n"
+ " if (count == 1) {\n"
+ " throw new Exception('foo')\n"
+ " }\n"
+ " echo 'Done!'\n"
+ "}\n",
true));

WorkflowRun run = r.buildAndAssertSuccess(p);
r.assertLogContains("Try #1", run);
r.assertLogContains("ERROR: Execution failed", run);
r.assertLogContains("java.lang.Exception: foo", run);
r.assertLogContains("\tat ", run);
r.assertLogContains("Try #2", run);
r.assertLogContains("Done!", run);
}
}