From c3da5c6ecc206505624c749a29e6278ee83f797c Mon Sep 17 00:00:00 2001 From: Leo-Fish <1957774799@qq.com> Date: Tue, 28 Oct 2025 01:06:22 -0500 Subject: [PATCH] fix: resolve flaky tests receiveMedicaidPregnancyEligible and testArray1 * Add sorting to ensure HashMap iteration order is deterministic --- .../export/flexporter/CustomFHIRPathResourceGeneratorR4.java | 5 +++++ .../behaviors/planeligibility/PlanEligibilityFinder.java | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/mitre/synthea/export/flexporter/CustomFHIRPathResourceGeneratorR4.java b/src/main/java/org/mitre/synthea/export/flexporter/CustomFHIRPathResourceGeneratorR4.java index 05f62aa2ec..72ba50241a 100644 --- a/src/main/java/org/mitre/synthea/export/flexporter/CustomFHIRPathResourceGeneratorR4.java +++ b/src/main/java/org/mitre/synthea/export/flexporter/CustomFHIRPathResourceGeneratorR4.java @@ -9,6 +9,7 @@ import ca.uhn.fhir.context.RuntimeResourceBlockDefinition; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -720,6 +721,10 @@ private List sortedPaths() { // the 3 above are the only options in the enum } } + + Collections.sort(whereEquals); + Collections.sort(whereUnequals); + Collections.sort(withoutWhere); List ret = new ArrayList(); ret.addAll(whereEquals); diff --git a/src/main/java/org/mitre/synthea/world/agents/behaviors/planeligibility/PlanEligibilityFinder.java b/src/main/java/org/mitre/synthea/world/agents/behaviors/planeligibility/PlanEligibilityFinder.java index e52b0271b2..7516b2c1ca 100644 --- a/src/main/java/org/mitre/synthea/world/agents/behaviors/planeligibility/PlanEligibilityFinder.java +++ b/src/main/java/org/mitre/synthea/world/agents/behaviors/planeligibility/PlanEligibilityFinder.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.LinkedHashMap; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; @@ -76,7 +77,7 @@ public static void buildPlanEligibilities(String state, String fileName) { private static Map removeBlankMapStringValues(Map map) { Map mapValuesToKeep = map.entrySet().stream() .filter(entry -> !StringUtils.isBlank(entry.getValue())).collect( - Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); return mapValuesToKeep; }