From 40a09c6c04ac4ac4fb6bf62c7d195a568711305b Mon Sep 17 00:00:00 2001 From: Ross Light Date: Thu, 21 Dec 2017 13:15:27 -0800 Subject: [PATCH] internal: fix flaky context test Change-Id: I877fbcfdde33559baabbda2c275164dd98256892 Reviewed-on: https://go-review.googlesource.com/85196 Reviewed-by: Brad Fitzpatrick --- internal/token_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/token_test.go b/internal/token_test.go index a52bb81..9118d82 100644 --- a/internal/token_test.go +++ b/internal/token_test.go @@ -94,14 +94,16 @@ func TestRetrieveTokenWithContexts(t *testing.T) { t.Errorf("RetrieveToken (with background context) = %v; want no error", err) } - ctx, cancelfunc := context.WithCancel(context.Background()) - + retrieved := make(chan struct{}) cancellingts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - cancelfunc() + <-retrieved })) defer cancellingts.Close() + ctx, cancel := context.WithCancel(context.Background()) + cancel() _, err = RetrieveToken(ctx, clientID, "", cancellingts.URL, url.Values{}) + close(retrieved) if err == nil { t.Errorf("RetrieveToken (with cancelled context) = nil; want error") }