@@ -33,6 +33,7 @@ import (
33
33
"google.golang.org/grpc/connectivity"
34
34
"google.golang.org/grpc/credentials/insecure"
35
35
"google.golang.org/grpc/internal/balancer/stub"
36
+ "google.golang.org/grpc/internal/grpcsync"
36
37
"google.golang.org/grpc/internal/grpctest"
37
38
"google.golang.org/grpc/internal/stubserver"
38
39
"google.golang.org/grpc/internal/testutils"
@@ -196,14 +197,14 @@ func (s) TestGoodUpdateThenResolverError(t *testing.T) {
196
197
backend := stubserver .StartTestService (t , nil )
197
198
defer backend .Stop ()
198
199
resolverStateReceived := false
199
- resolverErrorReceived := false
200
+ resolverErrorReceived := grpcsync . NewEvent ()
200
201
201
202
childBF := stub.BalancerFuncs {
202
203
Init : func (bd * stub.BalancerData ) {
203
204
bd .Data = balancer .Get (pickfirstleaf .Name ).Build (bd .ClientConn , bd .BuildOptions )
204
205
},
205
206
UpdateClientConnState : func (bd * stub.BalancerData , ccs balancer.ClientConnState ) error {
206
- if resolverErrorReceived {
207
+ if resolverErrorReceived . HasFired () {
207
208
t .Error ("Received resolver error before resolver state." )
208
209
}
209
210
resolverStateReceived = true
@@ -213,7 +214,7 @@ func (s) TestGoodUpdateThenResolverError(t *testing.T) {
213
214
if ! resolverStateReceived {
214
215
t .Error ("Received resolver error before resolver state." )
215
216
}
216
- resolverErrorReceived = true
217
+ resolverErrorReceived . Fire ()
217
218
bd .Data .(balancer.Balancer ).ResolverError (err )
218
219
},
219
220
Close : func (bd * stub.BalancerData ) {
@@ -286,8 +287,10 @@ func (s) TestGoodUpdateThenResolverError(t *testing.T) {
286
287
t .Fatalf ("Child balancer did not receive resolver state." )
287
288
}
288
289
289
- if ! resolverErrorReceived {
290
- t .Fatalf ("Child balancer did not receive error." )
290
+ select {
291
+ case <- resolverErrorReceived .Done ():
292
+ case <- ctx .Done ():
293
+ t .Fatal ("Context timed out waiting for resolver error to be delivered to child balancer." )
291
294
}
292
295
}
293
296
0 commit comments