From ecb92fd86d6cf6bd53a35004870014ed1e77e8f6 Mon Sep 17 00:00:00 2001 From: Koala Yeung Date: Wed, 7 Feb 2018 13:32:57 +0800 Subject: [PATCH] fix TestClient_canceled * 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. --- client_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client_test.go b/client_test.go index 319594a..8bdec7c 100644 --- a/client_test.go +++ b/client_test.go @@ -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 "+