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

Method TestBlockingPickTransientWaitforready

picker_wrapper_test.go:131–157  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

129}
130
131func (s) TestBlockingPickTransientWaitforready(t *testing.T) {
132 bp := newPickerWrapper()
133 bp.updatePicker(&testingPicker{err: balancer.ErrTransientFailure, maxCalled: goroutineCount})
134 var finishedCount uint64
135 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
136 defer cancel()
137 // All goroutines should block because picker returns transientFailure and
138 // picks are not failfast.
139 wg := sync.WaitGroup{}
140 wg.Add(goroutineCount)
141 for i := goroutineCount; i > 0; i-- {
142 go func() {
143 if pick, err := bp.pick(ctx, false, balancer.PickInfo{}); err != nil || pick.transport != testT {
144 t.Errorf("bp.pick returned transport: %v, error: %v, want transport: %v, error: nil", pick.transport, err, testT)
145 }
146 atomic.AddUint64(&finishedCount, 1)
147 wg.Done()
148 }()
149 }
150 time.Sleep(time.Millisecond)
151 if c := atomic.LoadUint64(&finishedCount); c != 0 {
152 t.Errorf("finished goroutines count: %v, want 0", c)
153 }
154 bp.updatePicker(&testingPicker{sc: testSC, maxCalled: goroutineCount})
155 // Wait for all pickers to finish before the context is cancelled.
156 wg.Wait()
157}
158
159func (s) TestBlockingPickSCNotReady(t *testing.T) {
160 bp := newPickerWrapper()

Callers

nothing calls this directly

Calls 7

newPickerWrapperFunction · 0.85
updatePickerMethod · 0.80
WaitMethod · 0.80
AddMethod · 0.65
ErrorfMethod · 0.65
pickMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected