testWRR is a deterministic WRR implementation. The real implementation does random WRR. testWRR makes the balancer behavior deterministic and easier to test. With {a: 2, b: 3}, the Next() results will be {a, a, b, b, b}.
| 32 | // |
| 33 | // With {a: 2, b: 3}, the Next() results will be {a, a, b, b, b}. |
| 34 | type testWRR struct { |
| 35 | itemsWithWeight []struct { |
| 36 | item any |
| 37 | weight int64 |
| 38 | } |
| 39 | length int |
| 40 | |
| 41 | mu sync.Mutex |
| 42 | idx int // The index of the item that will be picked |
| 43 | count int64 // The number of times the current item has been picked. |
| 44 | } |
| 45 | |
| 46 | // NewTestWRR return a WRR for testing. It's deterministic instead of random. |
| 47 | func NewTestWRR() wrr.WRR { |
nothing calls this directly
no outgoing calls
no test coverage detected