Skip to content

Commit

Permalink
[7.x] fix flaky test (backport #5574) (#5580)
Browse files Browse the repository at this point in the history
* fix flaky test (#5574)

use same ctx.WithTimeout in server and request.
previously we were using a separate ctx.

fixes #5571

(cherry picked from commit 846116b)

* make update

Co-authored-by: stuart nelson <[email protected]>
  • Loading branch information
mergify[bot] and stuartnelson3 authored Jun 30, 2021
1 parent c99bae7 commit fdb2c62
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions sourcemap/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ func TestFetchTimeout(t *testing.T) {
var (
errs int64

apikey = "supersecret"
name = "webapp"
version = "1.0.0"
path = "/my/path/to/bundle.js.map"
c = http.DefaultClient
apikey = "supersecret"
name = "webapp"
version = "1.0.0"
path = "/my/path/to/bundle.js.map"
c = http.DefaultClient
ctx, cancel = context.WithTimeout(context.Background(), time.Millisecond)
)
defer cancel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
<-r.Context().Done()
<-ctx.Done()
}))
defer ts.Close()

Expand All @@ -190,11 +192,7 @@ func TestFetchTimeout(t *testing.T) {
store, err := newStore(b, logger, time.Minute)
assert.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()

_, err = store.Fetch(ctx, name, version, path)
time.Sleep(10 * time.Millisecond)
assert.True(t, errors.Is(err, context.DeadlineExceeded))
atomic.AddInt64(&errs, 1)

Expand Down

0 comments on commit fdb2c62

Please sign in to comment.