Skip to content

Commit

Permalink
test: fix TestConcurrentRevokeAndGetValueBug test case
Browse files Browse the repository at this point in the history
  • Loading branch information
mahe-work committed Oct 26, 2021
1 parent aa648a3 commit 14336ce
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func TestItemWithShortestTTLIsRevokedWhenCacheFillsUp(t *testing.T) {
}
}

func TestConcurrentRefreshAndGetBug(t *testing.T) {
func TestConcurrentRefreshAndGetValueBug(t *testing.T) {
// Run refresh & revoke loops quicker than usual
defaultLoopInterval := loopInterval
defer func() {
loopInterval = defaultLoopInterval
}()
loopInterval = 10 * time.Millisecond
StartWith(1, 11, 1, 5*time.Second)
// continuously spam GetValue until we want to stop
// continuously spamming GetValue should manifest the bug
c := make(chan []byte, 1)
url := "https://httpbin.org/ip"
go busyGet(t, c, url)
Expand All @@ -140,15 +140,15 @@ func TestConcurrentRefreshAndGetBug(t *testing.T) {
assert.NotEqual(t, ci.Updating, true, "Item Should not be in updating state")
}

func TestRevocationDespiteUpdatingBug(t *testing.T) {
func TestConcurrentRevokeAndGetValueBug(t *testing.T) {
// Run refresh & revoke loops quicker than usual
defaultLoopInterval := loopInterval
defer func() {
loopInterval = defaultLoopInterval
}()
loopInterval = 10 * time.Millisecond
StartWith(1, 11, 1, 20*time.Millisecond)
// continuously spam GetValue until we want to stop
// Continuously spamming GetValue should force ConcurrentRefreshAndGetBug to manifest
c := make(chan []byte, 1)
url := "https://httpbin.org/ip"
go busyGet(t, c, url)
Expand All @@ -162,6 +162,7 @@ func TestRevocationDespiteUpdatingBug(t *testing.T) {
AddItem(i)
time.Sleep(1 * time.Second)
c <- []byte("stop")
time.Sleep(1 * time.Second)
assert.True(t, nil == GetValue(url), "Item should have been revoked by now")
}

Expand Down

0 comments on commit 14336ce

Please sign in to comment.