Skip to content

Commit 505ae15

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 505ae15

5 files changed

Lines changed: 38 additions & 9 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,

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public void noNamespaceSchemaLocationDownloadProblem() throws Exception {
8888
" \r\n" + //
8989
"</root-element>";
9090

91-
String xsdCachePath = CacheResourcesManager.getResourceCachePath("http://localhost:8080/sample.xsd").toString();
91+
String resourceUri = "http://localhost:8080/sample.xsd";
92+
String xsdCachePath = CacheResourcesManager.getResourceCachePath(resourceUri).toString();
9293
String fileURI = "test.xml";
9394
// Downloading...
9495
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls, pd(fileURI,
@@ -99,7 +100,8 @@ public void noNamespaceSchemaLocationDownloadProblem() throws Exception {
99100
new Diagnostic(r(0, 1, 0, 13), "cvc-elt.1.a: Cannot find the declaration of element 'root-element'.",
100101
DiagnosticSeverity.Error, "xml", XMLSchemaErrorCode.cvc_elt_1_a.getCode())));
101102

102-
TimeUnit.SECONDS.sleep(5); // HACK: to make the timing work on slow machines
103+
ContentModelManager contentModelManager = ls.getComponent(ContentModelManager.class);
104+
contentModelManager.waitForDownload(resourceUri);
103105

104106
// Downloaded error
105107
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls, pd(fileURI,
@@ -162,7 +164,8 @@ public void schemaLocationDownloadProblem() throws Exception {
162164
" \r\n" + //
163165
"</root-element>";
164166

165-
String xsdCachePath = CacheResourcesManager.getResourceCachePath("http://localhost:8080/sample.xsd").toString();
167+
String resourceUri = "http://localhost:8080/sample.xsd";
168+
String xsdCachePath = CacheResourcesManager.getResourceCachePath(resourceUri).toString();
166169
String fileURI = "test.xml";
167170
// Downloading...
168171
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls, pd(fileURI,
@@ -173,7 +176,8 @@ public void schemaLocationDownloadProblem() throws Exception {
173176
new Diagnostic(r(0, 1, 0, 13), "cvc-elt.1.a: Cannot find the declaration of element 'root-element'.",
174177
DiagnosticSeverity.Error, "xml", XMLSchemaErrorCode.cvc_elt_1_a.getCode())));
175178

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

178182
// Downloaded error
179183
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls, pd(fileURI,

0 commit comments

Comments
 (0)