@@ -80,7 +80,7 @@ func (s) TestADS_BackoffAfterStreamFailure(t *testing.T) {
8080 t .Logf ("Received LDS request for resources: %v" , req .GetResourceNames ())
8181 select {
8282 case ldsResourcesCh <- req .GetResourceNames ():
83- default :
83+ case <- ctx . Done () :
8484 }
8585 }
8686 // Return an error everytime a request is sent on the stream. This
@@ -92,7 +92,7 @@ func (s) TestADS_BackoffAfterStreamFailure(t *testing.T) {
9292 OnStreamClosed : func (int64 , * v3corepb.Node ) {
9393 select {
9494 case streamCloseCh <- struct {}{}:
95- default :
95+ case <- ctx . Done () :
9696 }
9797 },
9898 })
@@ -102,7 +102,7 @@ func (s) TestADS_BackoffAfterStreamFailure(t *testing.T) {
102102 streamBackoff := func (v int ) time.Duration {
103103 select {
104104 case backoffCh <- struct {}{}:
105- default :
105+ case <- ctx . Done () :
106106 }
107107 return 0
108108 }
@@ -179,7 +179,7 @@ func (s) TestADS_RetriesAfterBrokenStream(t *testing.T) {
179179 OnStreamRequest : func (_ int64 , req * v3discoverypb.DiscoveryRequest ) error {
180180 select {
181181 case streamRequestCh <- req :
182- default :
182+ case <- ctx . Done () :
183183 }
184184 return nil
185185 },
@@ -189,7 +189,7 @@ func (s) TestADS_RetriesAfterBrokenStream(t *testing.T) {
189189 OnStreamResponse : func (_ context.Context , _ int64 , _ * v3discoverypb.DiscoveryRequest , resp * v3discoverypb.DiscoveryResponse ) {
190190 select {
191191 case streamResponseCh <- resp :
192- default :
192+ case <- ctx . Done () :
193193 }
194194 },
195195 })
@@ -210,14 +210,12 @@ func (s) TestADS_RetriesAfterBrokenStream(t *testing.T) {
210210 // Override the backoff implementation to always return 0, to reduce test
211211 // run time. Instead control when the backoff returns by blocking on a
212212 // channel, that the test closes.
213- backoffCh := make (chan struct {}, 1 )
214- unblockBackoffCh := make (chan struct {})
213+ backoffCh := make (chan struct {})
215214 streamBackoff := func (v int ) time.Duration {
216215 select {
217216 case backoffCh <- struct {}{}:
218- default :
217+ case <- ctx . Done () :
219218 }
220- <- unblockBackoffCh
221219 return 0
222220 }
223221
@@ -293,17 +291,29 @@ func (s) TestADS_RetriesAfterBrokenStream(t *testing.T) {
293291 // Verify that the error callback on the watcher is not invoked.
294292 verifyNoListenerUpdate (ctx , lw .updateCh )
295293
296- // Wait for backoff to kick in.
294+ // Wait for backoff to kick in, and unblock the first backoff attempt .
297295 select {
298296 case <- backoffCh :
299297 case <- ctx .Done ():
300298 t .Fatal ("Timeout waiting for stream backoff" )
301299 }
302300
303- // Bring up the connection to the management server, and unblock the backoff
301+ // Bring up the management server. The test does not have prcecise control
302+ // over when new streams to the management server will start succeeding. The
303+ // ADS stream implementation will backoff as many times as required before
304+ // it can successfully create a new stream. Therefore, we need to receive on
305+ // the backoffCh as many times as required, and unblock the backoff
304306 // implementation.
305307 lis .Restart ()
306- close (unblockBackoffCh )
308+ go func () {
309+ for {
310+ select {
311+ case <- backoffCh :
312+ case <- ctx .Done ():
313+ return
314+ }
315+ }
316+ }()
307317
308318 // Verify that the transport creates a new stream and sends out a new
309319 // request which contains the previously acked version, but an empty nonce.
0 commit comments