increase test timing cor sync.cache

This commit is contained in:
Florian Schade
2021-01-19 23:23:41 +01:00
parent af870e005e
commit 4f80541b9f
+7 -7
View File
@@ -30,7 +30,7 @@ func BenchmarkCache(b *testing.B) {
size := 1024
c, cr := cacheRunner(size)
cr(func(i int) { c.Store(strconv.Itoa(i), i, time.Now().Add(10*time.Millisecond)) })
cr(func(i int) { c.Store(strconv.Itoa(i), i, time.Now().Add(100*time.Millisecond)) })
cr(func(i int) { c.Delete(strconv.Itoa(i)) })
}
@@ -38,14 +38,14 @@ func TestCache(t *testing.T) {
size := 1024
c, cr := cacheRunner(size)
cr(func(i int) { c.Store(strconv.Itoa(i), i, time.Now().Add(10*time.Millisecond)) })
cr(func(i int) { c.Store(strconv.Itoa(i), i, time.Now().Add(100*time.Millisecond)) })
assert.Equal(t, size, int(c.length), "length is atomic")
cr(func(i int) { c.Delete(strconv.Itoa(i)) })
assert.Equal(t, 0, int(c.length), "delete is atomic")
cr(func(i int) {
time.Sleep(11 * time.Millisecond)
time.Sleep(101 * time.Millisecond)
c.evict()
})
assert.Equal(t, 0, int(c.length), "evict is atomic")
@@ -68,7 +68,7 @@ func TestCache_Load(t *testing.T) {
})
cr(func(i int) {
wait := 10 * time.Millisecond
wait := 100 * time.Millisecond
c.Store(strconv.Itoa(i), i, time.Now().Add(wait))
time.Sleep(wait + 1)
assert.Nil(t, c.Load(strconv.Itoa(i)), "entry is nil if it's expired")
@@ -79,12 +79,12 @@ func TestCache_Store(t *testing.T) {
c, cr := cacheRunner(1024)
cr(func(i int) {
c.Store(strconv.Itoa(i), i, time.Now().Add(10*time.Millisecond))
c.Store(strconv.Itoa(i), i, time.Now().Add(100*time.Millisecond))
assert.Equal(t, i, c.Load(strconv.Itoa(i)).V, "new entries can be added")
})
cr(func(i int) {
replacedExpiration := time.Now().Add(10 * time.Millisecond)
replacedExpiration := time.Now().Add(10 * time.Minute)
c.Store(strconv.Itoa(i), "old", time.Now().Add(10*time.Minute))
c.Store(strconv.Itoa(i), "updated", replacedExpiration)
assert.Equal(t, "updated", c.Load(strconv.Itoa(i)).V, "entry values can be updated")
@@ -96,7 +96,7 @@ func TestCache_Delete(t *testing.T) {
c, cr := cacheRunner(1024)
cr(func(i int) {
c.Store(strconv.Itoa(i), i, time.Now().Add(10*time.Millisecond))
c.Store(strconv.Itoa(i), i, time.Now().Add(100*time.Millisecond))
c.Delete(strconv.Itoa(i))
assert.Nil(t, c.Load(strconv.Itoa(i)), "entries can be deleted")
})