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

Method TestBlockingPick

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

Source from the content-addressed store, hash-verified

76}
77
78func (s) TestBlockingPick(t *testing.T) {
79 bp := newPickerWrapper()
80 // All goroutines should block because picker is nil in bp.
81 var finishedCount uint64
82 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
83 defer cancel()
84 wg := sync.WaitGroup{}
85 wg.Add(goroutineCount)
86 for i := goroutineCount; i > 0; i-- {
87 go func() {
88 if pick, err := bp.pick(ctx, true, balancer.PickInfo{}); err != nil || pick.transport != testT {
89 t.Errorf("bp.pick returned transport: %v, error: %v, want transport: %v, error: nil", pick.transport, err, testT)
90 }
91 atomic.AddUint64(&finishedCount, 1)
92 wg.Done()
93 }()
94 }
95 time.Sleep(50 * time.Millisecond)
96 if c := atomic.LoadUint64(&finishedCount); c != 0 {
97 t.Errorf("finished goroutines count: %v, want 0", c)
98 }
99 bp.updatePicker(&testingPicker{sc: testSC, maxCalled: goroutineCount})
100 // Wait for all pickers to finish before the context is cancelled.
101 wg.Wait()
102}
103
104func (s) TestBlockingPickNoSubAvailable(t *testing.T) {
105 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