Skip to content

Commit 3b6ce15

Browse files
committed
give it a second try
1 parent 98da7b5 commit 3b6ce15

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

src/test/java/org/htmlunit/libraries/HtmxTest.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,44 @@
3333
*/
3434
@RunWith(BrowserRunner.class)
3535
public abstract class HtmxTest extends WebDriverTestCase {
36+
private static final int RETRIES = 2;
37+
private static final long RUN_TIME = 42 * DEFAULT_WAIT_TIME;
3638

3739
protected void htmx(final String subDir) throws Exception {
3840
startWebServer("src/test/resources/libraries/htmx/" + subDir, null, null);
3941

40-
final long runTime = 42 * DEFAULT_WAIT_TIME;
41-
final long endTime = System.currentTimeMillis() + runTime;
42-
4342
try {
43+
final String url = URL_FIRST + "test/index.html";
4444
final WebDriver webDriver = getWebDriver();
4545

4646
if (getWebDriver() instanceof HtmlUnitDriver) {
4747
getWebClient().getOptions().setThrowExceptionOnScriptError(false);
4848
}
4949

50-
final String url = URL_FIRST + "test/index.html";
51-
webDriver.get(url);
52-
5350
String lastStats = "";
54-
while (lastStats.length() == 0
55-
|| !lastStats.startsWith(getExpectedAlerts()[0])) {
56-
Thread.sleep(100);
57-
58-
if (System.currentTimeMillis() > endTime) {
59-
lastStats = "HtmxTest runs too long (longer than " + runTime / 1000 + "s) - "
60-
+ getResultElementText(webDriver);
61-
break;
51+
int tries = 0;
52+
while (tries < RETRIES) {
53+
tries++;
54+
55+
webDriver.get(url);
56+
57+
lastStats = "";
58+
final long endTime = System.currentTimeMillis() + RUN_TIME;
59+
while (lastStats.length() == 0 || !lastStats.startsWith(getExpectedAlerts()[0])) {
60+
if (lastStats.startsWith(getExpectedAlerts()[0])) {
61+
tries = RETRIES;
62+
break;
63+
}
64+
Thread.sleep(100);
65+
66+
if (System.currentTimeMillis() > endTime) {
67+
lastStats = "HtmxTest runs too long (longer than " + RUN_TIME / 1000 + "s) - "
68+
+ getResultElementText(webDriver);
69+
break;
70+
}
71+
72+
lastStats = getResultElementText(webDriver);
6273
}
63-
64-
lastStats = getResultElementText(webDriver);
6574
}
6675

6776
// bug hunting
@@ -77,11 +86,14 @@ protected void htmx(final String subDir) throws Exception {
7786
assertTrue(lastStats + "\n\n" + getErrors(webDriver), lastStats.startsWith(getExpectedAlerts()[0]));
7887
}
7988
catch (final Exception e) {
89+
// bug hunting
90+
/*
8091
e.printStackTrace();
8192
Throwable t = e;
8293
while ((t = t.getCause()) != null) {
8394
t.printStackTrace();
8495
}
96+
*/
8597
throw e;
8698
}
8799
}

0 commit comments

Comments
 (0)