forked from Mirrors/oauth2
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:
parent
197281d4e0
commit
40a09c6c04
|
@ -94,14 +94,16 @@ func TestRetrieveTokenWithContexts(t *testing.T) {
|
||||||
t.Errorf("RetrieveToken (with background context) = %v; want no error", err)
|
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) {
|
cancellingts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
cancelfunc()
|
<-retrieved
|
||||||
}))
|
}))
|
||||||
defer cancellingts.Close()
|
defer cancellingts.Close()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
_, err = RetrieveToken(ctx, clientID, "", cancellingts.URL, url.Values{})
|
_, err = RetrieveToken(ctx, clientID, "", cancellingts.URL, url.Values{})
|
||||||
|
close(retrieved)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("RetrieveToken (with cancelled context) = nil; want error")
|
t.Errorf("RetrieveToken (with cancelled context) = nil; want error")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue