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

Method TestBlockingPickNoSubAvailable

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

Source from the content-addressed store, hash-verified

102}
103
104func (s) TestBlockingPickNoSubAvailable(t *testing.T) {
105 bp := newPickerWrapper()
106 var finishedCount uint64
107 bp.updatePicker(&testingPicker{err: balancer.ErrNoSubConnAvailable, maxCalled: goroutineCount})
108 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
109 defer cancel()
110 // All goroutines should block because picker returns no subConn available.
111 wg := sync.WaitGroup{}
112 wg.Add(goroutineCount)
113 for i := goroutineCount; i > 0; i-- {
114 go func() {
115 if pick, err := bp.pick(ctx, true, balancer.PickInfo{}); err != nil || pick.transport != testT {
116 t.Errorf("bp.pick returned transport: %v, error: %v, want transport: %v, error: nil", pick.transport, err, testT)
117 }
118 atomic.AddUint64(&finishedCount, 1)
119 wg.Done()
120 }()
121 }
122 time.Sleep(50 * time.Millisecond)
123 if c := atomic.LoadUint64(&finishedCount); c != 0 {
124 t.Errorf("finished goroutines count: %v, want 0", c)
125 }
126 bp.updatePicker(&testingPicker{sc: testSC, maxCalled: goroutineCount})
127 // Wait for all pickers to finish before the context is cancelled.
128 wg.Wait()
129}
130
131func (s) TestBlockingPickTransientWaitforready(t *testing.T) {
132 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