Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/org/labkey/remoteapi/admin/ClearCachesCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.labkey.remoteapi.admin;

import org.labkey.remoteapi.CommandResponse;
import org.labkey.remoteapi.PostCommand;

import java.util.HashMap;
import java.util.Map;

public class ClearCachesCommand extends PostCommand<CommandResponse>
{
private final boolean _clearCaches;
private final boolean _gc;

public ClearCachesCommand(boolean clearCaches, boolean gc)
{
super("admin", "clearCaches");
_clearCaches = clearCaches;
_gc = gc;
}

@Override
protected Map<String, Object> createParameterMap()
{
Map<String, Object> params = new HashMap<>();
if (_clearCaches)
params.put("clearCaches", "1");
if (_gc)
params.put("gc", "1");
return params;
}
}
27 changes: 19 additions & 8 deletions src/org/labkey/test/BaseWebDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.labkey.remoteapi.CommandException;
import org.labkey.remoteapi.CommandResponse;
import org.labkey.remoteapi.Connection;
import org.labkey.remoteapi.admin.ClearCachesCommand;
import org.labkey.remoteapi.SimpleGetCommand;
import org.labkey.remoteapi.SimplePostCommand;
import org.labkey.remoteapi.collections.CaseInsensitiveHashMap;
Expand Down Expand Up @@ -99,7 +100,6 @@
import org.labkey.test.util.UIPermissionsHelper;
import org.labkey.test.util.core.webdav.WebDavUploadHelper;
import org.labkey.test.util.ext4cmp.Ext4FieldRef;
import org.labkey.test.util.query.QueryUtils;
import org.labkey.test.util.selenium.WebDriverUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.ElementClickInterceptedException;
Expand Down Expand Up @@ -1389,6 +1389,22 @@ public static File getDownloadDir()
return SingletonWebDriver.getInstance().getDownloadDir();
}

/**
* Clears all server caches and runs garbage collection via the admin ClearCachesAction.
* Leaves the browser on the MemTracker page.
*/
protected void clearCaches()
{
try
{
new ClearCachesCommand(true, true).execute(createDefaultConnection(), "/");
}
catch (IOException | CommandException e)
{
throw new RuntimeException("Failed to clear caches", e);
}
}

protected void checkLeaks()
{
if (isLeakCheckSkipped())
Expand All @@ -1415,7 +1431,8 @@ protected void checkLeaks()
}
}
msSinceTestStart = System.currentTimeMillis() - previousLeakCheck;
beginAt(WebTestHelper.buildURL("admin", "memTracker", Map.of("gc", 1, "clearCaches", 1)), 120000);
clearCaches();
beginAt(WebTestHelper.buildURL("admin", "memTracker"));
if (!isTextPresent("In-Use Objects"))
throw new IllegalStateException("Asserts must be enabled to track memory leaks; add -ea to your server VM params and restart or add -DmemCheck=false to your test VM params.");
leakCount = getImageWithAltTextCount("expand/collapse");
Expand Down Expand Up @@ -2379,12 +2396,6 @@ public void validateQueries(boolean validateSubfolders)
validateQueries(validateSubfolders, 120000);
}

@Deprecated
public void deleteAllRows(String projectName, String schema, String table) throws IOException, CommandException
{
QueryUtils.truncateTable(projectName, schema, table);
}

// This class makes it easier to start a specimen import early in a test and wait for completion later.
public class SpecimenImporter
{
Expand Down
2 changes: 1 addition & 1 deletion src/org/labkey/test/tests/filecontent/FilesQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void testNonFileBrowserFileRecords()
private void ensureFilesUpToDate()
{
log("Clear cache so that exp.files will do a sync immediately");
beginAt(WebTestHelper.buildURL("admin", "caches", Map.of("clearCaches", "1")), 120000);
clearCaches();
goToProjectHome();
}

Expand Down
6 changes: 3 additions & 3 deletions src/org/labkey/test/tests/perf/SchemaBrowserPerfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private long[] studyBaselineEmptyCache() {
long[] emptyCacheOpenStudyTimes = new long[5];
// run tests
for (int x = 0 ; x < 5; x++) {
beginAt(WebTestHelper.buildURL("admin", "caches", Map.of("clearCaches", 1)), 120000);
clearCaches();
goToHome();
clickProject(getProjectName());
goToSchemaBrowser();
Expand All @@ -103,7 +103,7 @@ private long[] studyBaselineEmptyCache() {
private long[] studyBaselineFullCache() {
long[] fullCacheOpenStudyTimes = new long[5];
// prepare cache
beginAt(WebTestHelper.buildURL("admin", "caches", Map.of("clearCaches", 1)), 120000);
clearCaches();
goToHome();
clickProject(getProjectName());
goToSchemaBrowser();
Expand All @@ -125,7 +125,7 @@ private long[] studyBaselineFullCache() {
private long[] studyDataBaselineFullCache() {
long[] emptyCacheOpenStudyDataTimes = new long[5];
// prepare cache
beginAt(WebTestHelper.buildURL("admin", "caches", Map.of("clearCaches", 1)), 120000);
clearCaches();
goToHome();
clickProject(getProjectName());
goToSchemaBrowser();
Expand Down
Loading