Skip to content

Commit

Permalink
fix TestClient_canceled
Browse files Browse the repository at this point in the history
* Cancel signal, if not probagated fast enough, should be allowed
  to have no effect at all.

* Fix occasional test error by artifically add time before reading
  the response. Expect to skip cases where cancel signal are not
  probagated before request finishing.
  • Loading branch information
yookoala committed Feb 7, 2018
1 parent 68b6ff0 commit ecb92fd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,16 @@ func TestClient_canceled(t *testing.T) {
innerCtx, cancel := context.WithCancel(r.Context())
req := NewRequest(c, r.WithContext(innerCtx))

// cancel before request
cancel()
select {
case <-time.After(time.Millisecond):
// artifically wait for some times
// to let the cancel signal kick in
}

// handle the result
resp, err := c.Do(req)
cancel() // cancel before reading
if err != nil {
http.Error(w, "failed to process request", http.StatusInternalServerError)
log.Printf("web server: unable to process request "+
Expand Down

0 comments on commit ecb92fd

Please sign in to comment.