MCPcopy
hub / github.com/grpc/grpc-go / testWRR

Struct testWRR

internal/testutils/wrr.go:34–44  ·  view source on GitHub ↗

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}.

Source from the content-addressed store, hash-verified

32//
33// With {a: 2, b: 3}, the Next() results will be {a, a, b, b, b}.
34type 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.
47func NewTestWRR() wrr.WRR {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected