@@ -78,9 +78,11 @@ func (s) TestBlockingPick(t *testing.T) {
7878 bp := newPickerWrapper (nil )
7979 // All goroutines should block because picker is nil in bp.
8080 var finishedCount uint64
81+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
82+ defer cancel ()
8183 for i := goroutineCount ; i > 0 ; i -- {
8284 go func () {
83- if tr , _ , err := bp .pick (context . Background () , true , balancer.PickInfo {}); err != nil || tr != testT {
85+ if tr , _ , err := bp .pick (ctx , true , balancer.PickInfo {}); err != nil || tr != testT {
8486 t .Errorf ("bp.pick returned non-nil error: %v" , err )
8587 }
8688 atomic .AddUint64 (& finishedCount , 1 )
@@ -97,10 +99,12 @@ func (s) TestBlockingPickNoSubAvailable(t *testing.T) {
9799 bp := newPickerWrapper (nil )
98100 var finishedCount uint64
99101 bp .updatePicker (& testingPicker {err : balancer .ErrNoSubConnAvailable , maxCalled : goroutineCount })
102+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
103+ defer cancel ()
100104 // All goroutines should block because picker returns no subConn available.
101105 for i := goroutineCount ; i > 0 ; i -- {
102106 go func () {
103- if tr , _ , err := bp .pick (context . Background () , true , balancer.PickInfo {}); err != nil || tr != testT {
107+ if tr , _ , err := bp .pick (ctx , true , balancer.PickInfo {}); err != nil || tr != testT {
104108 t .Errorf ("bp.pick returned non-nil error: %v" , err )
105109 }
106110 atomic .AddUint64 (& finishedCount , 1 )
@@ -117,11 +121,13 @@ func (s) TestBlockingPickTransientWaitforready(t *testing.T) {
117121 bp := newPickerWrapper (nil )
118122 bp .updatePicker (& testingPicker {err : balancer .ErrTransientFailure , maxCalled : goroutineCount })
119123 var finishedCount uint64
124+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
125+ defer cancel ()
120126 // All goroutines should block because picker returns transientFailure and
121127 // picks are not failfast.
122128 for i := goroutineCount ; i > 0 ; i -- {
123129 go func () {
124- if tr , _ , err := bp .pick (context . Background () , false , balancer.PickInfo {}); err != nil || tr != testT {
130+ if tr , _ , err := bp .pick (ctx , false , balancer.PickInfo {}); err != nil || tr != testT {
125131 t .Errorf ("bp.pick returned non-nil error: %v" , err )
126132 }
127133 atomic .AddUint64 (& finishedCount , 1 )
@@ -138,10 +144,12 @@ func (s) TestBlockingPickSCNotReady(t *testing.T) {
138144 bp := newPickerWrapper (nil )
139145 bp .updatePicker (& testingPicker {sc : testSCNotReady , maxCalled : goroutineCount })
140146 var finishedCount uint64
147+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
148+ defer cancel ()
141149 // All goroutines should block because subConn is not ready.
142150 for i := goroutineCount ; i > 0 ; i -- {
143151 go func () {
144- if tr , _ , err := bp .pick (context . Background () , true , balancer.PickInfo {}); err != nil || tr != testT {
152+ if tr , _ , err := bp .pick (ctx , true , balancer.PickInfo {}); err != nil || tr != testT {
145153 t .Errorf ("bp.pick returned non-nil error: %v" , err )
146154 }
147155 atomic .AddUint64 (& finishedCount , 1 )
0 commit comments