Skip to content

Commit d1aefe7

Browse files
committed
change all context usage in picker_wrapper_test to context.WithTimeout
1 parent aa71ff0 commit d1aefe7

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

picker_wrapper_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ import (
3232
"google.golang.org/grpc/status"
3333
)
3434

35-
const goroutineCount = 5
35+
const (
36+
goroutineCount = 5
37+
)
3638

3739
var (
3840
testT = &testTransport{}
@@ -80,7 +82,10 @@ func (s) TestBlockingPick(t *testing.T) {
8082
var finishedCount uint64
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+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
86+
defer cancel()
87+
88+
if tr, _, err := bp.pick(ctx, true, balancer.PickInfo{}); err != nil || tr != testT {
8489
t.Errorf("bp.pick returned non-nil error: %v", err)
8590
}
8691
atomic.AddUint64(&finishedCount, 1)
@@ -100,7 +105,10 @@ func (s) TestBlockingPickNoSubAvailable(t *testing.T) {
100105
// All goroutines should block because picker returns no subConn available.
101106
for i := goroutineCount; i > 0; i-- {
102107
go func() {
103-
if tr, _, err := bp.pick(context.Background(), true, balancer.PickInfo{}); err != nil || tr != testT {
108+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
109+
defer cancel()
110+
111+
if tr, _, err := bp.pick(ctx, true, balancer.PickInfo{}); err != nil || tr != testT {
104112
t.Errorf("bp.pick returned non-nil error: %v", err)
105113
}
106114
atomic.AddUint64(&finishedCount, 1)
@@ -121,7 +129,10 @@ func (s) TestBlockingPickTransientWaitforready(t *testing.T) {
121129
// picks are not failfast.
122130
for i := goroutineCount; i > 0; i-- {
123131
go func() {
124-
if tr, _, err := bp.pick(context.Background(), false, balancer.PickInfo{}); err != nil || tr != testT {
132+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
133+
defer cancel()
134+
135+
if tr, _, err := bp.pick(ctx, false, balancer.PickInfo{}); err != nil || tr != testT {
125136
t.Errorf("bp.pick returned non-nil error: %v", err)
126137
}
127138
atomic.AddUint64(&finishedCount, 1)
@@ -141,7 +152,10 @@ func (s) TestBlockingPickSCNotReady(t *testing.T) {
141152
// All goroutines should block because subConn is not ready.
142153
for i := goroutineCount; i > 0; i-- {
143154
go func() {
144-
if tr, _, err := bp.pick(context.Background(), true, balancer.PickInfo{}); err != nil || tr != testT {
155+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
156+
defer cancel()
157+
158+
if tr, _, err := bp.pick(ctx, true, balancer.PickInfo{}); err != nil || tr != testT {
145159
t.Errorf("bp.pick returned non-nil error: %v", err)
146160
}
147161
atomic.AddUint64(&finishedCount, 1)

0 commit comments

Comments
 (0)