From f6181fb6ff39d7565915839c61faecde98f3d913 Mon Sep 17 00:00:00 2001 From: TipzCM Date: Thu, 3 Feb 2022 18:30:58 -0500 Subject: [PATCH] 3354 fixing flakey tests (#3355) * 3354 fixing flakey tests * must fix code * updating number again * fixing test Co-authored-by: leif stawnyczy --- hapi-fhir-base/src/main/java/ca/uhn/fhir/i18n/Msg.java | 2 +- .../main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 3 ++- .../java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java | 5 ++--- .../fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java | 10 ++++++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/i18n/Msg.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/i18n/Msg.java index 77c32053fc3..a4c2017ece5 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/i18n/Msg.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/i18n/Msg.java @@ -25,7 +25,7 @@ public final class Msg { /** * IMPORTANT: Please update the following comment after you add a new code - * Last code value: 2018 + * Last code value: 2023 */ private Msg() {} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index ecaebec5c42..e117fe997ff 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -524,7 +524,8 @@ public abstract class BaseHapiFhirDao extends BaseStora .map(Throwable::getMessage) .collect(Collectors.joining(", ")); throw new InternalErrorException( - "Tag get/create failed after " + Msg.code(2023) + + "Tag get/create failed after " + TOTAL_TAG_READ_ATTEMPTS + " attempts with error(s): " + msg diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java index fc0d873e0ef..7d680fc7ab7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java @@ -177,7 +177,6 @@ public class BaseHapiFhirDaoTest { String scheme = "http://localhost"; String term = "code123"; String label = "hollow world"; - TransactionDetails transactionDetails = new TransactionDetails(); String raceConditionError = "Entity exists; if this is logged, you have race condition issues!"; TagDefinition tagDefinition = new TagDefinition(tagType, @@ -273,7 +272,7 @@ public class BaseHapiFhirDaoTest { Runnable task = () -> { latch.countDown(); try { - TagDefinition retTag = myTestDao.getTagOrNull(transactionDetails, tagType, scheme, term, label); + TagDefinition retTag = myTestDao.getTagOrNull(new TransactionDetails(), tagType, scheme, term, label); outcomes.put(retTag.hashCode(), retTag); counter.incrementAndGet(); } catch (Exception ex) { @@ -365,7 +364,7 @@ public class BaseHapiFhirDaoTest { fail(); } catch (Exception ex) { // verify - assertEquals("Tag get/create failed after 10 attempts with error(s): " + exMsg, ex.getMessage()); + assertTrue(ex.getMessage().contains("Tag get/create failed after 10 attempts with error(s): " + exMsg)); ArgumentCaptor appenderCaptor = ArgumentCaptor.forClass(ILoggingEvent.class); verify(myAppender, Mockito.times(10)) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java index 2690e7f91e4..b44f9cf4f66 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java @@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome; +import ca.uhn.fhir.jpa.config.TestR4Config; import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.model.entity.NormalizedQuantitySearchLevel; import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable; @@ -1012,7 +1013,10 @@ public class FhirResourceDaoR4CreateTest extends BaseJpaR4Test { @Test public void testResourceWithTagCreationNoFailures() throws ExecutionException, InterruptedException { - ExecutorService pool = Executors.newFixedThreadPool(5); + // we need to leave at least one free thread + // due to a REQUIRED_NEW transaction internally + int maxThreadsUsed = TestR4Config.ourMaxThreads - 1; + ExecutorService pool = Executors.newFixedThreadPool(Math.min(maxThreadsUsed, 5)); try { Coding tag = new Coding(); tag.setCode("code123"); @@ -1037,7 +1041,9 @@ public class FhirResourceDaoR4CreateTest extends BaseJpaR4Test { try { myPatientDao.update(updatePatient); } catch (ResourceVersionConflictException e) { - assertEquals("The operation has failed with a version constraint failure. This generally means that two clients/threads were trying to update the same resource at the same time, and this request was chosen as the failing request.", e.getMessage()); + assertTrue(e.getMessage().contains( + "The operation has failed with a version constraint failure. This generally means that two clients/threads were trying to update the same resource at the same time, and this request was chosen as the failing request." + )); } } catch (Exception e) { ourLog.error("Failure", e);