@@ -136,18 +136,23 @@ func TestStore_DistributionAcrossShards(t *testing.T) {
136136 })
137137
138138 // Generate many workflows and check distribution
139+ totalWorkflows := 100
139140 distribution := make (map [uint32 ]int )
140- for i := 0 ; i < 100 ; i ++ {
141+ for i := 0 ; i < totalWorkflows ; i ++ {
141142 wfID := "workflow-" + string (rune (i ))
142143 shard , err := store .GetShardForWorkflow (ctx , wfID )
143144 require .NoError (t , err )
144145 distribution [shard ]++
145146 }
146147
147- require .Equal (t , 38 , distribution [0 ], "Should have 29 workflows on shard 0" )
148- require .Equal (t , 29 , distribution [1 ], "Should have 33 workflows on shard 1" )
149- require .Equal (t , 33 , distribution [2 ], "Should have 33 workflows on shard 2" )
150- require .Equal (t , 100 , sum (distribution ), "Should have 100 workflows" )
148+ require .Equal (t , totalWorkflows , sum (distribution ), "Should have 100 workflows" )
149+
150+ // Each shard should have roughly 33% of workflows (±5%)
151+ for shard , count := range distribution {
152+ pct := float64 (count ) / 100.0 * 100
153+ require .GreaterOrEqual (t , pct , 28.0 , "Shard %d has too few workflows: %d%%" , shard , int (pct ))
154+ require .LessOrEqual (t , pct , 38.0 , "Shard %d has too many workflows: %d%%" , shard , int (pct ))
155+ }
151156}
152157
153158func sum (distribution map [uint32 ]int ) int {
0 commit comments