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

Method TestBlockingPickSCNotReady

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

Source from the content-addressed store, hash-verified

157}
158
159func (s) TestBlockingPickSCNotReady(t *testing.T) {
160 bp := newPickerWrapper()
161 bp.updatePicker(&testingPicker{sc: testSCNotReady, maxCalled: goroutineCount})
162 var finishedCount uint64
163 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
164 defer cancel()
165 // All goroutines should block because subConn is not ready.
166 wg := sync.WaitGroup{}
167 wg.Add(goroutineCount)
168 for i := goroutineCount; i > 0; i-- {
169 go func() {
170 if pick, err := bp.pick(ctx, true, balancer.PickInfo{}); err != nil || pick.transport != testT {
171 t.Errorf("bp.pick returned transport: %v, error: %v, want transport: %v, error: nil", pick.transport, err, testT)
172 }
173 atomic.AddUint64(&finishedCount, 1)
174 wg.Done()
175 }()
176 }
177 time.Sleep(time.Millisecond)
178 if c := atomic.LoadUint64(&finishedCount); c != 0 {
179 t.Errorf("finished goroutines count: %v, want 0", c)
180 }
181 bp.updatePicker(&testingPicker{sc: testSC, maxCalled: goroutineCount})
182 // Wait for all pickers to finish before the context is cancelled.
183 wg.Wait()
184}

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