internal: fix flaky context test

Change-Id: I877fbcfdde33559baabbda2c275164dd98256892
Reviewed-on: https://go-review.googlesource.com/85196
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ross Light 2017-12-21 13:15:27 -08:00
parent 197281d4e0
commit 40a09c6c04
1 changed files with 5 additions and 3 deletions

View File

@ -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")
}