From 02de3e49e39e3e9c7481e0e26df9d9e788971be4 Mon Sep 17 00:00:00 2001 From: William Denton Date: Sat, 7 Jan 2023 11:49:35 -0800 Subject: [PATCH] Fix some issues with 'mvn test' on windows (#4223) * fix handling of Windows line ends * some tests need to wait a little longer for things to get done * Windows path separator fix * simpler lineend fix * more timeouts and another path separator issue * redo some timeout issues * Issue in Windows: URI is not hierarchical * another timeout issue --- .../ca/uhn/fhir/checks/HapiErrorCodeCheckTest.java | 2 +- .../ca/uhn/fhir/cli/UploadTerminologyCommandTest.java | 2 +- .../email/EmailSubscriptionDstu2Test.java | 2 +- .../jpa/subscription/email/EmailSenderImplTest.java | 2 +- .../email/EmailSubscriptionDstu3Test.java | 4 ++-- .../ca/uhn/fhir/jpa/bulk/BulkExportUseCaseTest.java | 5 +++-- .../fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java | 2 +- .../ca/uhn/fhir/jpa/bulk/imprt2/BulkImportR4Test.java | 5 +++-- .../test/java/ca/uhn/fhir/jpa/packages/NpmR4Test.java | 5 ++++- .../ca/uhn/fhir/jpa/util/MemoryCacheServiceTest.java | 2 +- .../uhn/fhir/rest/openapi/OpenApiInterceptorTest.java | 11 ++++++++++- .../java/ca/uhn/fhir/rest/server/mail/MailSvcIT.java | 6 +++--- .../java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java | 4 ++-- .../java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java | 2 +- 14 files changed, 34 insertions(+), 20 deletions(-) diff --git a/hapi-fhir-checkstyle/src/test/java/ca/uhn/fhir/checks/HapiErrorCodeCheckTest.java b/hapi-fhir-checkstyle/src/test/java/ca/uhn/fhir/checks/HapiErrorCodeCheckTest.java index 662662adb7d..fb0ae2bf889 100644 --- a/hapi-fhir-checkstyle/src/test/java/ca/uhn/fhir/checks/HapiErrorCodeCheckTest.java +++ b/hapi-fhir-checkstyle/src/test/java/ca/uhn/fhir/checks/HapiErrorCodeCheckTest.java @@ -42,7 +42,7 @@ class HapiErrorCodeCheckTest { checker.process(files); // validate - String[] errorLines = errors.toString().split("\n"); + String[] errorLines = errors.toString().split("\r?\n"); Arrays.stream(errorLines).forEach(ourLog::info); assertEquals(2, errorLines.length); assertThat(errorLines[0], startsWith("[ERROR] ")); diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java index 0502e8c6858..dc47d18f309 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java @@ -331,7 +331,7 @@ public class UploadTerminologyCommandTest { )); fail(); } catch (Error e) { - assertThat(e.toString(), Matchers.containsString("FileNotFoundException: target/concepts.csv/foo.csv")); + assertThat(e.toString().replace('\\', '/'), Matchers.containsString("FileNotFoundException: target/concepts.csv/foo.csv")); } } diff --git a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu2Test.java b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu2Test.java index 5e13bfc0b13..1747d12c233 100644 --- a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu2Test.java +++ b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu2Test.java @@ -128,7 +128,7 @@ public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test { Observation observation1 = sendObservation(code, "SNOMED-CT"); - assertTrue(ourGreenMail.waitForIncomingEmail(1000, 1)); + assertTrue(ourGreenMail.waitForIncomingEmail(10000, 1)); MimeMessage[] messages = ourGreenMail.getReceivedMessages(); assertEquals(2, messages.length); diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSenderImplTest.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSenderImplTest.java index 6ac7c8796e3..fc8c57571a6 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSenderImplTest.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSenderImplTest.java @@ -46,7 +46,7 @@ public class EmailSenderImplTest { details.setBodyTemplate("foo"); fixture.send(details); - assertTrue(ourGreenMail.waitForIncomingEmail(1000, 1)); + assertTrue(ourGreenMail.waitForIncomingEmail(10000, 1)); MimeMessage[] messages = ourGreenMail.getReceivedMessages(); assertEquals(2, messages.length); diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java index a1a53eab9e5..2458a593fea 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java @@ -151,7 +151,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { sendObservation(code, "SNOMED-CT"); waitForQueueToDrain(); - assertTrue(ourGreenMail.waitForIncomingEmail(1000, 1)); + assertTrue(ourGreenMail.waitForIncomingEmail(10000, 1)); List received = Arrays.asList(ourGreenMail.getReceivedMessages()); assertEquals(1, received.get(0).getFrom().length); @@ -196,7 +196,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { sendObservation(code, "SNOMED-CT"); waitForQueueToDrain(); - assertTrue(ourGreenMail.waitForIncomingEmail(1000, 1)); + assertTrue(ourGreenMail.waitForIncomingEmail(10000, 1)); List received = Arrays.asList(ourGreenMail.getReceivedMessages()); assertEquals(1, received.size()); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkExportUseCaseTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkExportUseCaseTest.java index 6bca18c08b5..0ee9854bc5d 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkExportUseCaseTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkExportUseCaseTest.java @@ -52,6 +52,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.concurrent.TimeUnit; import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.is; @@ -1061,9 +1062,9 @@ public class BulkExportUseCaseTest extends BaseResourceProviderR4Test { assertNotNull(startResponse); - myBatch2JobHelper.awaitJobCompletion(startResponse.getJobId()); + myBatch2JobHelper.awaitJobCompletion(startResponse.getJobId(), 60); - await().until(() -> myJobRunner.getJobInfo(startResponse.getJobId()).getReport() != null); + await().atMost(300, TimeUnit.SECONDS).until(() -> myJobRunner.getJobInfo(startResponse.getJobId()).getReport() != null); String report = myJobRunner.getJobInfo(startResponse.getJobId()).getReport(); BulkExportJobResults results = JsonUtil.deserialize(report, BulkExportJobResults.class); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java index 049888321f5..a4ab9daf426 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java @@ -169,7 +169,7 @@ public class BulkDataImportR4Test extends BaseJpaR4Test implements ITestDataBuil ActivateJobResult activateJobOutcome = mySvc.activateNextReadyJob(); assertTrue(activateJobOutcome.isActivated); - JobInstance instance = myBatch2JobHelper.awaitJobCompletion(activateJobOutcome.jobId); + JobInstance instance = myBatch2JobHelper.awaitJobCompletion(activateJobOutcome.jobId, 60); assertNotNull(instance); assertEquals(StatusEnum.COMPLETED, instance.getStatus()); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt2/BulkImportR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt2/BulkImportR4Test.java index 899c66d2132..957688d8706 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt2/BulkImportR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt2/BulkImportR4Test.java @@ -34,6 +34,7 @@ import org.springframework.data.domain.Pageable; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static org.awaitility.Awaitility.await; @@ -101,7 +102,7 @@ public class BulkImportR4Test extends BaseJpaR4Test { // Verify - await().until(() -> { + await().atMost(120, TimeUnit.SECONDS).until(() -> { myJobCleanerService.runMaintenancePass(); JobInstance instance = myJobCoordinator.getInstance(instanceId); return instance.getStatus(); @@ -185,7 +186,7 @@ public class BulkImportR4Test extends BaseJpaR4Test { return storage; }); - await().until(() -> { + await().atMost(120, TimeUnit.SECONDS).until(() -> { myJobCleanerService.runMaintenancePass(); JobInstance instance = myJobCoordinator.getInstance(instanceId); return instance.getErrorCount(); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/NpmR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/NpmR4Test.java index 739904f7f0b..49a757f6bab 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/NpmR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/NpmR4Test.java @@ -936,7 +936,10 @@ public class NpmR4Test extends BaseJpaR4Test { public void testInstallR4PackageFromFile() { Path currentRelativePath = Paths.get(""); - String s = currentRelativePath.toAbsolutePath().toString(); + String s = currentRelativePath.toAbsolutePath().toString().replace('\\', '/'); + if (s.charAt(0) != '/' && s.charAt(1) == ':') { // is Windows.. + s = s.substring(2); // .. get rid of the "C:" part (not perfect but... + } System.out.println("Current absolute path is: " + s); String fileUrl = "file:" + s + "/src/test/resources/packages/de.basisprofil.r4-1.2.0.tgz"; diff --git a/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/util/MemoryCacheServiceTest.java b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/util/MemoryCacheServiceTest.java index 767a5469a5d..d6ca6835a6a 100644 --- a/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/util/MemoryCacheServiceTest.java +++ b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/util/MemoryCacheServiceTest.java @@ -214,7 +214,7 @@ class MemoryCacheServiceTest { public Integer getOrTimeout(String theMessage) throws InterruptedException, ExecutionException { try { - return future.get(1, TimeUnit.SECONDS); + return future.get(60, TimeUnit.SECONDS); } catch (TimeoutException e) { fail(theMessage); return null; diff --git a/hapi-fhir-server-openapi/src/test/java/ca/uhn/fhir/rest/openapi/OpenApiInterceptorTest.java b/hapi-fhir-server-openapi/src/test/java/ca/uhn/fhir/rest/openapi/OpenApiInterceptorTest.java index 89a02348dd9..175a23848ff 100644 --- a/hapi-fhir-server-openapi/src/test/java/ca/uhn/fhir/rest/openapi/OpenApiInterceptorTest.java +++ b/hapi-fhir-server-openapi/src/test/java/ca/uhn/fhir/rest/openapi/OpenApiInterceptorTest.java @@ -27,6 +27,7 @@ import io.swagger.v3.core.util.Yaml; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.PathItem; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; @@ -218,9 +219,17 @@ public class OpenApiInterceptorTest { font-size: 1.1em; } """; - assertEquals(expected, resp); + assertEquals(removeCtrlR(expected), removeCtrlR(resp)); } + protected String removeCtrlR (String source) { + String result = source; + if (source != null) { + result = StringUtils.remove(source, '\r'); + } + return result; + } + @Test public void testSwaggerUiNotPaged() throws IOException { myServer.getRestfulServer().registerInterceptor(new AddResourceCountsInterceptor()); diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/mail/MailSvcIT.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/mail/MailSvcIT.java index 206a623ff6f..c62c965f250 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/mail/MailSvcIT.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/mail/MailSvcIT.java @@ -42,7 +42,7 @@ public class MailSvcIT { // execute fixture.sendMail(email); // validate - assertTrue(ourGreenMail.waitForIncomingEmail(1000, 1)); + assertTrue(ourGreenMail.waitForIncomingEmail(5000, 1)); final MimeMessage[] receivedMessages = ourGreenMail.getReceivedMessages(); assertEquals(1, receivedMessages.length); assertEquals(SUBJECT, receivedMessages[0].getSubject()); @@ -56,7 +56,7 @@ public class MailSvcIT { // execute fixture.sendMail(emails); // validate - assertTrue(ourGreenMail.waitForIncomingEmail(1000, emails.size())); + assertTrue(ourGreenMail.waitForIncomingEmail(15000, emails.size())); final MimeMessage[] receivedMessages = ourGreenMail.getReceivedMessages(); assertEquals(emails.size(), receivedMessages.length); assertEquals(SUBJECT, receivedMessages[0].getSubject()); @@ -76,7 +76,7 @@ public class MailSvcIT { fixture.sendMail(email); // validate - assertTrue(ourGreenMail.waitForIncomingEmail(1000, 0)); + assertTrue(ourGreenMail.waitForIncomingEmail(5000, 0)); final MimeMessage[] receivedMessages = ourGreenMail.getReceivedMessages(); assertEquals(0, receivedMessages.length); } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java index 639c9748cae..ece0e8c65e1 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java @@ -110,7 +110,7 @@ public class FhirContextDstu2Test { } }); } - assertConcurrent("Unable to encode resources multithreaded", runnables, 1000); + assertConcurrent("Unable to encode resources multithreaded", runnables, 30000); } private void parseStringResourceMultipleTimesWithClass(IParser iParser, String medicationOrderResource) { @@ -163,7 +163,7 @@ public class FhirContextDstu2Test { }); } // wait until all threads are ready - assertTrue(allExecutorThreadsReady.await(runnables.size() * 10L, TimeUnit.MILLISECONDS), "Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent"); + assertTrue(allExecutorThreadsReady.await(runnables.size() * 1000L, TimeUnit.MILLISECONDS), "Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent"); // start all test runners afterInitBlocker.countDown(); assertTrue(allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS), message + " timeout! More than" + maxTimeoutSeconds + "seconds"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java index 14e43f79bf3..4724e1c3e55 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java @@ -271,7 +271,7 @@ public class BinaryDstu2Test { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); - int timeout = 5; + int timeout = 60; RequestConfig config = RequestConfig.custom() .setConnectTimeout(timeout * 1000) .setConnectionRequestTimeout(timeout * 1000)