From 764d923518b8d262c7e8a1cc9b226f7a94f93e9b Mon Sep 17 00:00:00 2001 From: yujun Date: Thu, 27 Jun 2024 22:54:50 +0800 Subject: [PATCH] [fix](fe ut) fix unstable SystemInfoServiceTest (#36893) For a random alg, (max -min) < 5% is too unstable. Make this diff bigger, change it to 30%. --- .../doris/system/SystemInfoServiceTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/system/SystemInfoServiceTest.java b/fe/fe-core/src/test/java/org/apache/doris/system/SystemInfoServiceTest.java index e933c0df17c4e8..eb1f33c288902f 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/system/SystemInfoServiceTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/system/SystemInfoServiceTest.java @@ -46,6 +46,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; public class SystemInfoServiceTest { private SystemInfoService infoService; @@ -403,7 +405,7 @@ public void testSelectBackendIdsForReplicaCreation() throws Exception { ReplicaAllocation replicaAlloc = ReplicaAllocation.DEFAULT_ALLOCATION; // also check if the random selection logic can evenly distribute the replica. Map beCounterMap = Maps.newHashMap(); - for (int i = 0; i < 10000; ++i) { + for (int i = 0; i < 30000; ++i) { Pair>, TStorageMedium> ret = infoService.selectBackendIdsForReplicaCreation(replicaAlloc, Maps.newHashMap(), TStorageMedium.HDD, false, false); Map> res = ret.first; @@ -412,11 +414,16 @@ public void testSelectBackendIdsForReplicaCreation() throws Exception { beCounterMap.put(beId, beCounterMap.getOrDefault(beId, 0) + 1); } } + Set expectBackendIds = infoService.getMixBackends().stream() + .filter(Backend::isAlive).map(Backend::getId) + .collect(Collectors.toSet()); + Assert.assertEquals(expectBackendIds, beCounterMap.keySet().stream().collect(Collectors.toSet())); List list = Lists.newArrayList(beCounterMap.values()); Collections.sort(list); - int diff = list.get(list.size() - 1) - list.get(0); - // The max replica num and min replica num's diff is less than 5%. - Assert.assertTrue((diff * 1.0 / list.get(0)) < 0.05); + int max = list.get(list.size() - 1); + int diff = max - list.get(0); + // The max replica num and min replica num's diff is less than 30%. + Assert.assertTrue((diff * 1.0 / max) < 0.3); } private void addDisk(Backend be, String path, TStorageMedium medium, long totalB, long availB) {