Skip to content

Commit a88cf81

Browse files
committed
Stabilize two test that seem to often fail on the CI
Signed-off-by: azerr <azerr@redhat.com>
1 parent 3ee1cfd commit a88cf81

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/model/ContentModelManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,8 @@ public void forceDownloadExternalResource(String url) {
546546
cacheResolverExtension.forceDownloadExternalResource(url);
547547
}
548548

549+
public void waitForDownload(String resourceUri) {
550+
cacheResolverExtension.waitForDownload(resourceUri);
551+
}
552+
549553
}

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/uriresolver/XMLCacheResolverExtension.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,8 @@ public void evictCache() throws IOException {
172172
public void forceDownloadExternalResource(String url) {
173173
cacheResourcesManager.forceDownloadExternalResource(url);
174174
}
175+
176+
public void waitForDownload(String resourceUri) {
177+
cacheResourcesManager.waitForDownload(resourceUri);
178+
}
175179
}

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/uriresolver/CacheResourcesManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Map;
3232
import java.util.Set;
3333
import java.util.concurrent.CompletableFuture;
34+
import java.util.concurrent.ExecutionException;
3435
import java.util.concurrent.TimeUnit;
3536
import java.util.logging.Level;
3637
import java.util.logging.Logger;
@@ -492,4 +493,16 @@ public void forceDownloadExternalResource(String url) {
492493
private boolean isForceDownloadExternalResource(String url) {
493494
return forceDownloadExternalResources.getIfPresent(url) != null;
494495
}
496+
497+
public void waitForDownload(String resourceUri) {
498+
CompletableFuture<Path> downloadedFile = resourcesLoading.get(resourceUri);
499+
if (downloadedFile != null) {
500+
try {
501+
downloadedFile.get();
502+
} catch (InterruptedException e) {
503+
Thread.currentThread().interrupt();
504+
} catch (ExecutionException e) {
505+
}
506+
}
507+
}
495508
}

org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLValidationExternalResourcesBasedOnDTDTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public void docTypeDownloadProblem() throws Exception {
8383
"<root-element>\r\n" + //
8484
"</root-element>";
8585

86-
String dtdCachePath = CacheResourcesManager.getResourceCachePath("http://localhost:8080/sample.dtd").toString();
86+
String resourceUri = "http://localhost:8080/sample.dtd";
87+
String dtdCachePath = CacheResourcesManager.getResourceCachePath(resourceUri).toString();
8788
String fileURI = "test.xml";
8889
// Downloading...
8990
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls,
@@ -96,8 +97,9 @@ public void docTypeDownloadProblem() throws Exception {
9697
new Diagnostic(r(1, 1, 1, 13), "Element type \"root-element\" must be declared.",
9798
DiagnosticSeverity.Error, "xml", DTDErrorCode.MSG_ELEMENT_NOT_DECLARED.getCode())));
9899

99-
TimeUnit.SECONDS.sleep(5); // HACK: to make the timing work on slow machines
100-
100+
ContentModelManager contentModelManager = ls.getComponent(ContentModelManager.class);
101+
contentModelManager.waitForDownload(resourceUri);
102+
101103
// Downloaded error
102104
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls,
103105
pd(fileURI,
@@ -164,7 +166,8 @@ public void entityRefDownloadProblem() throws Exception {
164166
" &abcd;\r\n" + //
165167
"</root-element>";
166168

167-
String dtdCachePath = CacheResourcesManager.getResourceCachePath("http://localhost:8080/sample.dtd").toString();
169+
String resourceUri = "http://localhost:8080/sample.dtd";
170+
String dtdCachePath = CacheResourcesManager.getResourceCachePath(resourceUri).toString();
168171
String fileURI = "test.xml";
169172
// Downloading...
170173
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls,
@@ -177,7 +180,8 @@ public void entityRefDownloadProblem() throws Exception {
177180
new Diagnostic(r(6, 1, 6, 7), "The entity \"abcd\" was referenced, but not declared.",
178181
DiagnosticSeverity.Error, "xml", DTDErrorCode.EntityNotDeclared.getCode())));
179182

180-
TimeUnit.SECONDS.sleep(5); // HACK: to make the timing work on slow machines
183+
ContentModelManager contentModelManager = ls.getComponent(ContentModelManager.class);
184+
contentModelManager.waitForDownload(resourceUri);
181185

182186
// Downloaded error
183187
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls,

0 commit comments

Comments
 (0)