Skip to content

Commit

Permalink
Cache test uses polling to adapt to system speed
Browse files Browse the repository at this point in the history
Instead of waiting a fixed amount of time for a download,
the cache tests use repeated polling to check if the download has finished.
This means that on fast systems, the tests will run faster,
and on slow systems there should be less random failure.

Fixes eclipse-lemminx#753

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Sep 22, 2020
1 parent 3ea8abb commit 8ccaf15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.eclipse.lemminx.XMLAssert.pd;
import static org.eclipse.lemminx.XMLAssert.r;

import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import org.eclipse.lemminx.AbstractCacheBasedTest;
Expand Down Expand Up @@ -140,6 +141,8 @@ public void schemaWithUrlWithCache() throws Exception {
"</invoice> \r\n" + //
"";

TimeUnit.MILLISECONDS.sleep(500);

String expectedLocation = TEST_WORK_DIRECTORY.resolve("cache/http/invoice.xsd").toString();
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, configuration,
pd(fileURI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,18 @@ public void testUnavailableCache() throws Exception {
fail("cacheResourcesManager should be busy downloading the url");
} catch (CacheResourceDownloadingException ignored) {
}
TimeUnit.MILLISECONDS.sleep(200);
// failed to download so returns null
assertNull(cacheResourcesManager.getResource(uri));

boolean downloaded = false;
int i = 0;
while (!downloaded && i < 9) {
try {
TimeUnit.MILLISECONDS.sleep(100);
assertNull(cacheResourcesManager.getResource(uri));
downloaded = true;
} catch (CacheResourceDownloadingException e) {
}
i++;
}

TimeUnit.SECONDS.sleep(1);// wait past the cache expiration date

Expand All @@ -95,8 +104,18 @@ public void testAvailableCache() throws Exception {
fail("cacheResourcesManager should be busy downloading the url");
} catch (CacheResourceDownloadingException ignored) {
}
TimeUnit.MILLISECONDS.sleep(200);
assertNotNull(cacheResourcesManager.getResource(uri));

boolean downloaded = false;
int i = 0;
while (!downloaded && i < 9) {
try {
TimeUnit.MILLISECONDS.sleep(100);
assertNotNull(cacheResourcesManager.getResource(uri));
downloaded = true;
} catch (CacheResourceDownloadingException e) {
}
i++;
}

server.stop();
TimeUnit.SECONDS.sleep(1);// wait past the cache expiration date
Expand Down

0 comments on commit 8ccaf15

Please sign in to comment.