Skip to content

Commit

Permalink
test(issuercache): avoid race conditions for reload intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Sep 13, 2024
1 parent 596d0e7 commit efc486c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions issuercache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
"github.com/google/go-cmp/cmp"
)

// Serves as barrier to avoid race conditions during reload intervals.
const delta = 100 * time.Millisecond

type requestFn func(token string) *http.Request

type userFn func(issuerUrl string) *User
Expand Down Expand Up @@ -270,7 +273,7 @@ func TestMultiIssuerCache_reload(t *testing.T) {
},
}
// wait for reload
time.Sleep(2 * time.Second)
time.Sleep(2*time.Second - delta)

assert.Equal(t, 2, calls)
assert.Len(t, ic.cache, 1)
Expand All @@ -293,7 +296,7 @@ func TestMultiIssuerCache_retryFailing(t *testing.T) {
assert.Empty(t, ic.cache)

// wait for reload
time.Sleep(2 * time.Second)
time.Sleep(2*time.Second - delta)

assert.Equal(t, 4, calls)
assert.Empty(t, ic.cache)
Expand Down Expand Up @@ -329,7 +332,7 @@ func TestMultiIssuerCache_retrySecondReload(t *testing.T) {
},
}
// wait for reload
time.Sleep(2 * time.Second)
time.Sleep(2*time.Second - delta)

assert.Equal(t, 3, calls)
assert.Len(t, ic.cache, 1)
Expand Down

0 comments on commit efc486c

Please sign in to comment.