Skip to content

Commit ca3a3e3

Browse files
authored
Minor test fixes for intermittent failures (#2828)
- Wait for file browser checkbox to appear - Stop running server-side JUnit tests after 5 consecutive timeouts - Add missing `conceptURI` to `ColumnType.VisitLabel` - Add retry to `ProjectMenu.open`
1 parent 6a4b986 commit ca3a3e3

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

src/org/labkey/test/components/core/ProjectMenu.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.labkey.test.components.core;
1717

18+
import org.apache.commons.lang3.StringUtils;
1819
import org.labkey.test.Locator;
1920
import org.labkey.test.WebDriverWrapper;
2021
import org.labkey.test.components.Component;
@@ -28,6 +29,7 @@
2829

2930
import java.util.List;
3031

32+
import static org.labkey.test.Locators.loadingSpinner;
3133
import static org.labkey.test.WebDriverWrapper.WAIT_FOR_JAVASCRIPT;
3234

3335
/**
@@ -68,20 +70,27 @@ public String getCurrentProject()
6870

6971
private boolean isOpen()
7072
{
71-
return elementCache().menuContainer.getAttribute("class").contains("open");
73+
return StringUtils.trimToEmpty(elementCache().menuContainer.getAttribute("class")).contains("open") &&
74+
!loadingSpinner.existsIn(elementCache().menuContainer);
7275
}
7376

7477
public ProjectMenu open()
7578
{
7679
if (!isOpen())
7780
{
78-
getWrapper().executeScript("window.scrollTo(0,0);");
79-
if (getWrapper().isElementPresent(Locator.css("li.dropdown.open > .lk-custom-dropdown-menu")))
80-
getWrapper().mouseOver(elementCache().menuToggle); // Just need to hover if another menu is already open
81-
else
82-
elementCache().menuToggle.click();
83-
WebDriverWrapper.waitFor(this::isOpen, "Project menu didn't open", 2000);
84-
getWrapper().waitForElement(Locator.tagWithClass("div", "folder-nav"));
81+
Runnable openMenu = () -> {
82+
getWrapper().executeScript("window.scrollTo(0,0);");
83+
if (getWrapper().isElementPresent(Locator.css("li.dropdown.open > .lk-custom-dropdown-menu")))
84+
getWrapper().mouseOver(elementCache().menuToggle); // Just need to hover if another menu is already open
85+
else
86+
elementCache().menuToggle.click();
87+
WebDriverWrapper.waitFor(this::isOpen, "Project menu didn't open", 2000);
88+
};
89+
openMenu.run();
90+
if (!Locator.tagWithClass("div", "folder-nav").existsIn(this))
91+
{
92+
openMenu.run(); // retry
93+
}
8594
}
8695
return this;
8796
}
@@ -222,7 +231,7 @@ protected ElementCache newElementCache()
222231
return new ElementCache();
223232
}
224233

225-
protected class ElementCache extends Component.ElementCache
234+
protected class ElementCache extends Component<ElementCache>.ElementCache
226235
{
227236
final WebElement menuContainer = Locators.menuProjectNav.refindWhenNeeded(getComponentElement());
228237
final WebElement menuToggle = Locator.tagWithAttribute("a", "data-toggle", "dropdown").refindWhenNeeded(menuContainer);

src/org/labkey/test/params/FieldDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ public boolean isMeasureByDefault()
590590
ColumnType OntologyLookup = new ColumnTypeImpl("Ontology Lookup", "string", "http://www.labkey.org/types#conceptCode", null);
591591
ColumnType VisitId = new ColumnTypeImpl("Visit ID", "double", "http://cpas.labkey.com/Study#VisitId", null);
592592
ColumnType VisitDate = new ColumnTypeImpl("Visit Date", "dateTime", "http://cpas.labkey.com/Study#VisitId", null);
593-
ColumnType VisitLabel = new ColumnTypeImpl("Visit Label", "string");
593+
ColumnType VisitLabel = new ColumnTypeImpl("Visit Label", "string", "http://cpas.labkey.com/Study#VisitId", null);
594594
ColumnType Sample = new ColumnTypeImpl("Sample", "int", "http://www.labkey.org/exp/xml#sample", new IntLookup( "exp", "Materials"));
595595
ColumnType Barcode = new ColumnTypeImpl("Unique ID", "string", "http://www.labkey.org/types#storageUniqueId", null);
596596
ColumnType TextChoice = new ColumnTypeImpl("Text Choice", "string", "http://www.labkey.org/types#textChoice", null);

src/org/labkey/test/tests/JUnitTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.json.JSONException;
3737
import org.json.JSONObject;
3838
import org.junit.Assert;
39+
import org.junit.Assume;
3940
import org.junit.experimental.categories.Category;
4041
import org.labkey.remoteapi.CommandException;
4142
import org.labkey.remoteapi.CommandResponse;
@@ -69,6 +70,7 @@
6970
import java.util.List;
7071
import java.util.Map;
7172
import java.util.Set;
73+
import java.util.concurrent.atomic.AtomicInteger;
7274
import java.util.function.Predicate;
7375

7476
@Category({BVT.class, UnitTests.class})
@@ -318,6 +320,7 @@ else if (responseBody.contains("<title>Upgrade Status</title>") ||
318320
boolean addedHeader = false;
319321
for (String key : json.keySet())
320322
{
323+
AtomicInteger ioeCounter = new AtomicInteger(0);
321324
TestSuite testsuite = new TestSuite(key);
322325
JSONArray testClassArray = json.getJSONArray(key);
323326
// Individual tests include both the class name and the requested timeout
@@ -331,7 +334,7 @@ else if (responseBody.contains("<title>Upgrade Status</title>") ||
331334
// Timeout is represented in seconds
332335
int timeout = testClass.getInt("timeout");
333336
if (accept.test(testClass.toMap()))
334-
testsuite.addTest(new RemoteTest(className, timeout));
337+
testsuite.addTest(new RemoteTest(className, timeout, ioeCounter));
335338
}
336339

337340
}
@@ -370,23 +373,27 @@ else if (responseBody.contains("<title>Upgrade Status</title>") ||
370373
@SuppressWarnings("JUnitMalformedDeclaration")
371374
public static class RemoteTest extends TestCase
372375
{
373-
String _remoteClass;
376+
private final String _remoteClass;
374377
/** Timeout in seconds to wait for the whole testcase to finish on the server */
375378
private final int _timeout;
379+
// Skip tests after a certain number of IOExceptions
380+
private final AtomicInteger _ioeCounter;
376381

377382
/** Stash and reuse so that we can keep using the same session instead of re-authenticating with every request */
378383
private static final Connection connection = WebTestHelper.getRemoteApiConnection();
379384

380-
public RemoteTest(String remoteClass, int timeout)
385+
public RemoteTest(String remoteClass, int timeout, AtomicInteger ioeCounter)
381386
{
382387
super(remoteClass);
383388
_remoteClass = remoteClass;
384389
_timeout = timeout;
390+
_ioeCounter = ioeCounter;
385391
}
386392

387393
@Override
388394
protected void runTest()
389395
{
396+
Assume.assumeTrue("Too many consecutive test timeouts", _ioeCounter.get() < 5);
390397
long startTime = System.currentTimeMillis();
391398
try
392399
{
@@ -405,16 +412,19 @@ else if (resultJson.get("wasSuccessful") != Boolean.TRUE)
405412
WebTestHelper.logToServer(getLogTestString("successful", startTime) + ", " + dump(resultJson, false), connection);
406413
LOG.info(getLogTestString("successful", startTime));
407414
LOG.info(dump(resultJson, true));
415+
_ioeCounter.set(0);
408416
}
409417
catch (SocketTimeoutException ste)
410418
{
419+
_ioeCounter.incrementAndGet();
411420
String timed_out = getLogTestString("timed out", startTime);
412421
LOG.error(timed_out);
413422
ArtifactCollector.dumpThreads();
414423
throw new RuntimeException(timed_out, ste);
415424
}
416425
catch (IOException ioe)
417426
{
427+
_ioeCounter.incrementAndGet();
418428
String message = getLogTestString("failed: " + ioe.getMessage(), startTime);
419429
LOG.error(message);
420430
throw new RuntimeException(message, ioe);

src/org/labkey/test/util/FileBrowserHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private void checkFileBrowserFileCheckbox(String fileName, boolean checkTheBox)
248248
final Checkbox checkbox;
249249
try
250250
{
251-
checkbox = Ext4Checkbox().locatedBy(Locators.gridRowCheckbox(fileName)).find(getDriver());
251+
checkbox = Ext4Checkbox().locatedBy(Locators.gridRowCheckbox(fileName)).timeout(1_000).find(getDriver());
252252
}
253253
catch (NoSuchElementException nse)
254254
{

src/org/labkey/test/util/TestLogger.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ public static void log(String str)
138138
}
139139

140140
/**
141-
* Format an elapsed time to be suitable for log messages.
142-
* Over one minute:
143-
* " &lt;1m 25s&gt;"
144-
* Over one minute:
145-
* " &lt;8.059s&gt;"
146-
* Less than on second:
141+
* Format an elapsed time to be suitable for log messages.<br>
142+
* Over one minute:<br>
143+
* " &lt;1m 25s&gt;"<br>
144+
* Over one second:<br>
145+
* " &lt;8.059s&gt;"<br>
146+
* Less than one second:<br>
147147
* " &lt;125ms&gt;"
148148
* @param milliseconds Elapsed time in milliseconds
149149
* @return Formatted time

0 commit comments

Comments
 (0)