@@ -32,7 +32,9 @@ import (
32
32
"google.golang.org/grpc/status"
33
33
)
34
34
35
- const goroutineCount = 5
35
+ const (
36
+ goroutineCount = 5
37
+ )
36
38
37
39
var (
38
40
testT = & testTransport {}
@@ -80,7 +82,10 @@ func (s) TestBlockingPick(t *testing.T) {
80
82
var finishedCount uint64
81
83
for i := goroutineCount ; i > 0 ; i -- {
82
84
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 {
84
89
t .Errorf ("bp.pick returned non-nil error: %v" , err )
85
90
}
86
91
atomic .AddUint64 (& finishedCount , 1 )
@@ -100,7 +105,10 @@ func (s) TestBlockingPickNoSubAvailable(t *testing.T) {
100
105
// All goroutines should block because picker returns no subConn available.
101
106
for i := goroutineCount ; i > 0 ; i -- {
102
107
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 {
104
112
t .Errorf ("bp.pick returned non-nil error: %v" , err )
105
113
}
106
114
atomic .AddUint64 (& finishedCount , 1 )
@@ -121,7 +129,10 @@ func (s) TestBlockingPickTransientWaitforready(t *testing.T) {
121
129
// picks are not failfast.
122
130
for i := goroutineCount ; i > 0 ; i -- {
123
131
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 {
125
136
t .Errorf ("bp.pick returned non-nil error: %v" , err )
126
137
}
127
138
atomic .AddUint64 (& finishedCount , 1 )
@@ -141,7 +152,10 @@ func (s) TestBlockingPickSCNotReady(t *testing.T) {
141
152
// All goroutines should block because subConn is not ready.
142
153
for i := goroutineCount ; i > 0 ; i -- {
143
154
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 {
145
159
t .Errorf ("bp.pick returned non-nil error: %v" , err )
146
160
}
147
161
atomic .AddUint64 (& finishedCount , 1 )
0 commit comments