Skip to content

Commit

Permalink
client-go: fix flake in test TestRequestWatchWithRetry
Browse files Browse the repository at this point in the history
Kubernetes-commit: e797a5a1989373275311b745faf0ff97f5d61000
  • Loading branch information
tkashem authored and k8s-publishing-bot committed Jun 4, 2021
1 parent bbd71da commit fc210d9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions rest/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,16 @@ func TestRequestStreamWithRetry(t *testing.T) {

func TestRequestWatchWithRetry(t *testing.T) {
testRequestWithRetry(t, "Watch", func(ctx context.Context, r *Request) {
r.Watch(ctx)
w, err := r.Watch(ctx)
if err == nil {
// in this test the the response body returned by the server is always empty,
// this will cause StreamWatcher.receive() to:
// - return an io.EOF to indicate that the watch closed normally and
// - then close the io.Reader
// since we assert on the number of times 'Close' has been called on the
// body of the response object, we need to wait here to avoid race condition.
<-w.ResultChan()
}
})
}

Expand Down Expand Up @@ -2870,8 +2879,9 @@ func testRequestWithRetry(t *testing.T, key string, doFunc func(ctx context.Cont
"Watch": {
attempts: 3,
reqCount: &count{closes: 0, seeks: make([]seek, 2)},
// we don't close the the Body of the final successful response
respCount: &count{closes: 1, seeks: []seek{}},
// the Body of the successful response object will get closed by
// StreamWatcher, so we need to take that into account.
respCount: &count{closes: 2, seeks: []seek{}},
},
"Stream": {
attempts: 2,
Expand Down

0 comments on commit fc210d9

Please sign in to comment.