提交 e50d4d71 编写于 作者: B Baptiste Mathus

Retry assertion for 10 seconds before failing

Also reduce the time 250 ms (instead of 1 second previously) between
retries to hopefully reduce the test duration on quick enough setups,
and still degrade nicely on less performing ones.
上级 1396c7f7
......@@ -198,6 +198,12 @@ THE SOFTWARE.
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -50,6 +50,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
......@@ -213,7 +214,6 @@ public class QuietDownCommandTest {
try {
threadPool.submit(exec_task);
beforeCli.block();
Thread.sleep(1000); // Left a room for calling CLI
assertJenkinsInQuietMode();
exec_task.get(10, TimeUnit.SECONDS);
} catch (TimeoutException e) {
......@@ -259,7 +259,6 @@ public class QuietDownCommandTest {
try {
threadPool.submit(exec_task);
beforeCli.block();
Thread.sleep(1000); // Left a room for calling CLI
assertJenkinsInQuietMode();
exec_task.get(10, TimeUnit.SECONDS);
} catch (TimeoutException e) {
......@@ -307,7 +306,6 @@ public class QuietDownCommandTest {
});
threadPool.submit(exec_task);
beforeCli.block();
Thread.sleep(1000); // Left a room for calling CLI
assertJenkinsInQuietMode();
try {
exec_task.get(2*TIMEOUT, TimeUnit.MILLISECONDS);
......@@ -351,7 +349,6 @@ public class QuietDownCommandTest {
});
threadPool.submit(exec_task);
beforeCli.block();
Thread.sleep(1000); // Left a room for calling CLI
assertJenkinsInQuietMode();
final boolean timeout_occured = false;
try {
......@@ -400,7 +397,6 @@ public class QuietDownCommandTest {
});
threadPool.submit(exec_task);
beforeCli.block();
Thread.sleep(1000); // Left a room for calling CLI
assertJenkinsInQuietMode();
finish.signal();
......@@ -427,7 +423,6 @@ public class QuietDownCommandTest {
final Future<FreeStyleBuild> build = OnlineNodeCommandTest.startBlockingAndFinishingBuild(project, finish);
assertThat(((FreeStyleProject) j.jenkins.getItem("aProject")).getBuilds(), hasSize(1));
boolean timeoutOccurred = false;
final FutureTask exec_task = new FutureTask(new Callable() {
public Object call() {
assertJenkinsNotInQuietMode();
......@@ -445,7 +440,6 @@ public class QuietDownCommandTest {
});
threadPool.submit(exec_task);
beforeCli.block();
Thread.sleep(1000); // Left a room for calling CLI
assertJenkinsInQuietMode();
finish.signal();
......@@ -457,19 +451,39 @@ public class QuietDownCommandTest {
exec_task.get(1, TimeUnit.SECONDS);
}
/**
* Asserts if Jenkins is in quiet mode.
* Will retry for some time before actually failing.
*/
private final void assertJenkinsInQuietMode() {
assertJenkinsInQuietMode(j);
}
/**
* Asserts if Jenkins is <strong>not</strong> in quiet mode.
* Will retry for some time before actually failing.
*/
private final void assertJenkinsNotInQuietMode() {
assertJenkinsNotInQuietMode(j);
}
/**
* Asserts if Jenkins is in quiet mode, retrying for some time before failing.
* @throws TimeoutException
*/
public static final void assertJenkinsInQuietMode(final JenkinsRule j) {
assertThat(j.jenkins.getActiveInstance().getQueue().isBlockedByShutdown(task), equalTo(true));
await().pollInterval(250, TimeUnit.MILLISECONDS)
.atMost(10, TimeUnit.SECONDS)
.until(() -> j.jenkins.getActiveInstance().getQueue().isBlockedByShutdown(task));
}
/**
* Asserts if Jenkins is <strong>not</strong> in quiet mode, retrying for some time before failing.
* @throws TimeoutException
*/
public static final void assertJenkinsNotInQuietMode(final JenkinsRule j) {
assertThat(j.jenkins.getActiveInstance().getQueue().isBlockedByShutdown(task), equalTo(false));
await().pollInterval(250, TimeUnit.MILLISECONDS)
.atMost(10, TimeUnit.SECONDS)
.until(() -> !j.jenkins.getActiveInstance().getQueue().isBlockedByShutdown(task));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册