diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/DTDHoverExtensionsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/DTDHoverExtensionsTest.java index 01cc4dd115..175232aed3 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/DTDHoverExtensionsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/DTDHoverExtensionsTest.java @@ -77,11 +77,15 @@ public void webXML() throws Exception { // Download the DTD by waiting 1 sec CacheResourcesManager cacheResourcesManager = new CacheResourcesManager(); - try { - cacheResourcesManager.getResource(httpDTDUri); - } catch (CacheResourceDownloadingException ignored) { + boolean downloaded = false; + while (!downloaded) { + try { + cacheResourcesManager.getResource(httpDTDUri); + downloaded = true; + } catch (CacheResourceDownloadingException ignored) { + TimeUnit.MILLISECONDS.sleep(100); + } } - TimeUnit.MILLISECONDS.sleep(1000); assertTrue(Files.exists(cachedFilePath), "'" + cachedFilePath + "' file should be downloaded in the cache."); diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/uriresolver/CacheResourcesManagerTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/uriresolver/CacheResourcesManagerTest.java index f780d845d6..59fb2b79ba 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/uriresolver/CacheResourcesManagerTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/uriresolver/CacheResourcesManagerTest.java @@ -71,11 +71,20 @@ 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)); - TimeUnit.SECONDS.sleep(1);// wait past the cache expiration date + 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(2);// wait past the cache expiration date // Manager should retry downloading try { @@ -95,11 +104,21 @@ 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 + TimeUnit.SECONDS.sleep(2);// wait past the cache expiration date // Manager should return cached content, even if server is offline assertNotNull(cacheResourcesManager.getResource(uri));