Skip to content

Commit

Permalink
Merge pull request #32387 from snazy/experiment-tests
Browse files Browse the repository at this point in the history
Update Test timeouts for Windows
  • Loading branch information
gsmet authored Apr 4, 2023
2 parents 366b825 + 06fe6e5 commit 9b8b5fb
Showing 1 changed file with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionTimeoutException;

Expand Down Expand Up @@ -42,36 +39,33 @@ public ContinuousTestingMavenTestUtils(URL url) {
}

public TestStatus waitForNextCompletion() {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
Awaitility.waitAtMost(1, TimeUnit.MINUTES).pollInterval(50, TimeUnit.MILLISECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
TestStatus ts = objectMapper.readValue(url, TestStatus.class);
if (ts.getLastRun() > runtToWaitFor) {
throw new RuntimeException(
"Waiting for run " + runtToWaitFor + " but run " + ts.getLastRun() + " has already occurred");
}
boolean runComplete = ts.getLastRun() == runtToWaitFor;
if (runComplete && ts.getRunning() > 0) {
//there is a small chance of a race, where changes are picked up twice, due to how filesystems work
//this works around it by waiting for the next run
runtToWaitFor = ts.getRunning();
return false;
} else if (runComplete) {
runtToWaitFor++;
}
return runComplete;
try {
Awaitility.waitAtMost(2, TimeUnit.MINUTES).pollInterval(200, TimeUnit.MILLISECONDS).until(() -> {
TestStatus ts = objectMapper.readValue(url, TestStatus.class);
if (ts.getLastRun() > runtToWaitFor) {
throw new RuntimeException(
"Waiting for run " + runtToWaitFor + " but run " + ts.getLastRun() + " has already occurred");
}
boolean runComplete = ts.getLastRun() == runtToWaitFor;
if (runComplete && ts.getRunning() > 0) {
//there is a small chance of a race, where changes are picked up twice, due to how filesystems work
//this works around it by waiting for the next run
runtToWaitFor = ts.getRunning();
return false;
} else if (runComplete) {
runtToWaitFor++;
}
return runComplete;
});
return objectMapper.readValue(url, TestStatus.class);
} catch (Exception e) {
TestStatus ts = null;
TestStatus ts;
try {
ts = objectMapper.readValue(url, TestStatus.class);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
throw new ConditionTimeoutException("Failed to wait for test run" + runtToWaitFor + " " + ts);
throw new ConditionTimeoutException("Failed to wait for test run " + runtToWaitFor + " " + ts, e);
}
}

Expand Down

0 comments on commit 9b8b5fb

Please sign in to comment.