Skip to content

Commit e55819e

Browse files
authored
lazy: Use channel to wait for resolver error being received in test (#8088)
1 parent b524c08 commit e55819e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

balancer/lazy/lazy_ext_test.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"google.golang.org/grpc/connectivity"
3434
"google.golang.org/grpc/credentials/insecure"
3535
"google.golang.org/grpc/internal/balancer/stub"
36+
"google.golang.org/grpc/internal/grpcsync"
3637
"google.golang.org/grpc/internal/grpctest"
3738
"google.golang.org/grpc/internal/stubserver"
3839
"google.golang.org/grpc/internal/testutils"
@@ -196,14 +197,14 @@ func (s) TestGoodUpdateThenResolverError(t *testing.T) {
196197
backend := stubserver.StartTestService(t, nil)
197198
defer backend.Stop()
198199
resolverStateReceived := false
199-
resolverErrorReceived := false
200+
resolverErrorReceived := grpcsync.NewEvent()
200201

201202
childBF := stub.BalancerFuncs{
202203
Init: func(bd *stub.BalancerData) {
203204
bd.Data = balancer.Get(pickfirstleaf.Name).Build(bd.ClientConn, bd.BuildOptions)
204205
},
205206
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error {
206-
if resolverErrorReceived {
207+
if resolverErrorReceived.HasFired() {
207208
t.Error("Received resolver error before resolver state.")
208209
}
209210
resolverStateReceived = true
@@ -213,7 +214,7 @@ func (s) TestGoodUpdateThenResolverError(t *testing.T) {
213214
if !resolverStateReceived {
214215
t.Error("Received resolver error before resolver state.")
215216
}
216-
resolverErrorReceived = true
217+
resolverErrorReceived.Fire()
217218
bd.Data.(balancer.Balancer).ResolverError(err)
218219
},
219220
Close: func(bd *stub.BalancerData) {
@@ -286,8 +287,10 @@ func (s) TestGoodUpdateThenResolverError(t *testing.T) {
286287
t.Fatalf("Child balancer did not receive resolver state.")
287288
}
288289

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.")
291294
}
292295
}
293296

0 commit comments

Comments
 (0)