3354 fixing flakey tests (#3355)

* 3354 fixing flakey tests

* must fix code

* updating number again

* fixing test

Co-authored-by: leif stawnyczy <leifstawnyczy@leifs-MacBook-Pro.local>
This commit is contained in:
TipzCM 2022-02-03 18:30:58 -05:00 committed by GitHub
parent c42ecc5c08
commit f6181fb6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

View File

@ -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() {}

View File

@ -524,7 +524,8 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> 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

View File

@ -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<ILoggingEvent> appenderCaptor = ArgumentCaptor.forClass(ILoggingEvent.class);
verify(myAppender, Mockito.times(10))

View File

@ -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);