Skip to content

Commit

Permalink
enforce keys sorting in test
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Nov 11, 2019
1 parent d9a12f5 commit 8551b64
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion expirable_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lcw

import (
"fmt"
"sort"
"sync/atomic"
"testing"
"time"
Expand All @@ -23,7 +24,10 @@ func TestExpirableCache(t *testing.T) {

assert.Equal(t, 5, lc.Stat().Keys)
assert.Equal(t, int64(5), lc.Stat().Misses)
assert.Equal(t, []string{"key-0", "key-1", "key-2", "key-3", "key-4"}, lc.Keys())

keys := lc.Keys()[:]
sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
assert.EqualValues(t, []string{"key-0", "key-1", "key-2", "key-3", "key-4"}, keys)

_, e := lc.Get("key-xx", func() (Value, error) {
return "result-xx", nil
Expand Down
5 changes: 4 additions & 1 deletion lru_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"net/http"
"sort"
"sync/atomic"
"testing"

Expand All @@ -28,7 +29,9 @@ func TestLruCache_MaxKeys(t *testing.T) {
assert.Equal(t, int32(i+1), atomic.LoadInt32(&coldCalls))
}

assert.Equal(t, []string{"key-0", "key-1", "key-2", "key-3", "key-4"}, lc.Keys())
keys := lc.Keys()[:]
sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
assert.EqualValues(t, []string{"key-0", "key-1", "key-2", "key-3", "key-4"}, keys)

// check if really cached
res, err := lc.Get("key-3", func() (Value, error) {
Expand Down
6 changes: 5 additions & 1 deletion redis_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"sort"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -45,7 +46,10 @@ func TestExpirableRedisCache(t *testing.T) {

assert.Equal(t, 5, lc.Stat().Keys)
assert.Equal(t, int64(5), lc.Stat().Misses)
assert.Equal(t, []string{"key-0", "key-1", "key-2", "key-3", "key-4"}, lc.Keys())

keys := lc.Keys()[:]
sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
assert.EqualValues(t, []string{"key-0", "key-1", "key-2", "key-3", "key-4"}, keys)

_, e := lc.Get("key-xx", func() (Value, error) {
return "result-xx", nil
Expand Down

0 comments on commit 8551b64

Please sign in to comment.