This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new 6bbf75686 fix(test): stabilize flaky multiplyConditionRoute test 
(#3192)
6bbf75686 is described below

commit 6bbf7568691a67de03dea7a6931b705182a19813
Author: CAICAII <[email protected]>
AuthorDate: Thu Feb 5 13:44:01 2026 +0800

    fix(test): stabilize flaky multiplyConditionRoute test (#3192)
    
    - Increase sample size from 1000 to 5000 for statistical stability
    - Use percentage-based tolerance (max 25% or 50) instead of fixed ±50
    - Accumulate weights for same-length results to avoid map key collision
    - Improve assertion with descriptive error message
    
    Fixes: #3176
---
 cluster/router/condition/router_test.go | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/cluster/router/condition/router_test.go 
b/cluster/router/condition/router_test.go
index 7509f591c..14938baae 100644
--- a/cluster/router/condition/router_test.go
+++ b/cluster/router/condition/router_test.go
@@ -1350,17 +1350,21 @@ conditions:
                                }
                        } else {
                                // check multiply destination route 
successfully or not
-                               ans := map[any]float32{}
+                               // Use larger sample size for statistical 
stability
+                               const sampleSize = 5000
+                               ans := map[int]float32{}
                                for _, s := range tt.multiDestination {
                                        args := struct {
                                                invokers   []base.Invoker
                                                url        *common.URL
                                                invocation base.Invocation
                                        }{tt.args.invokers[:], 
tt.args.url.Clone(), tt.args.invocation}
-                                       
ans[len(s.invokers_filters.filtrate(args.invokers, tt.args.url, 
tt.args.invocation))] = s.weight * 1000
+                                       key := 
len(s.invokers_filters.filtrate(args.invokers, tt.args.url, tt.args.invocation))
+                                       // Accumulate weights for same-length 
results to avoid map key collision
+                                       ans[key] += s.weight * sampleSize
                                }
-                               res := map[any]int{}
-                               for i := 0; i < 1000; i++ {
+                               res := map[int]int{}
+                               for i := 0; i < sampleSize; i++ {
                                        args := struct {
                                                invokers   []base.Invoker
                                                url        *common.URL
@@ -1368,11 +1372,17 @@ conditions:
                                        }{tt.args.invokers[:], 
tt.args.url.Clone(), tt.args.invocation}
                                        res[len(d.Route(args.invokers, 
args.url, args.invocation))]++
                                }
-                               for k, v := range ans {
-                                       if float32(res[k]+50) > v && 
float32(res[k]-50) < v {
-                                       } else {
-                                               assert.Fail(t, "out of range")
+                               for k, expected := range ans {
+                                       actual := float32(res[k])
+                                       // Use percentage-based tolerance: 
max(25% of expected, 50) to handle both
+                                       // high and low expected values while 
accounting for statistical variance
+                                       tolerance := expected * 0.25
+                                       if tolerance < 50 {
+                                               tolerance = 50
                                        }
+                                       assert.Truef(t, actual >= 
expected-tolerance && actual <= expected+tolerance,
+                                               "result count out of range for 
key=%d: expected=%.0f, actual=%.0f, tolerance=%.0f",
+                                               k, expected, actual, tolerance)
                                }
                        }
                })

Reply via email to