From d0c6b1aab61b7162db051ad43c6c93a6d940e037 Mon Sep 17 00:00:00 2001 From: FishGoddess <1149062639@qq.com> Date: Wed, 15 Nov 2023 23:55:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A7=84=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FUTURE.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FUTURE.md b/FUTURE.md index ac8a047..3ea524d 100644 --- a/FUTURE.md +++ b/FUTURE.md @@ -2,7 +2,9 @@ ### v0.5.x -* [ ] 提供一个清空并设置全量值的方法,方便定时数据的全量替换 +* [ ] ~~提供一个清空并设置全量值的方法,方便定时数据的全量替换~~ + 目前还找不到一个合适的设计去加入这个功能,并且也不是非常刚需,通过业务手段可以处理,所以先不加 +* [ ] 完善监控上报器,提供更多缓存信息查询的方法 ### v0.4.x @@ -24,7 +26,6 @@ * [x] 给 Reporter 增加缓存类型方法,主要用于监控不同类型缓存的使用情况 * [ ] ~~增加对不存在的数据做防穿透的机制~~ 经过实践,这个更适合业务方自己处理,所以这边就先去掉了 -* [ ] 完善监控上报器,提供更多缓存信息查询的方法 ### v0.3.x From 58665b61298aab16dc4f843d1792e36c63fa4dac Mon Sep 17 00:00:00 2001 From: FishGoddess <1149062639@qq.com> Date: Thu, 30 Nov 2023 00:21:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 10 ++- HISTORY.md | 7 +++ cache_test.go | 90 +++++++++++++-------------- config_test.go | 2 +- doc.go | 2 +- entry_test.go | 38 +++++------ global_test.go | 16 ++--- lfu_test.go | 18 +++--- load_test.go | 18 +++--- lru_test.go | 12 ++-- option_test.go | 36 +++++------ pkg/clock/clock_test.go | 4 +- pkg/heap/heap_test.go | 40 ++++++------ pkg/singleflight/singleflight_test.go | 20 +++--- pkg/task/task_test.go | 14 ++--- report_test.go | 68 ++++++++++---------- sharding_test.go | 4 +- standard_test.go | 4 +- 18 files changed, 208 insertions(+), 195 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5ea9152..d790f05 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,8 +9,14 @@ jobs: test-project: runs-on: ubuntu-20.04 steps: + - name: Setup + uses: actions/setup-go@v4 + with: + go-version: "1.17" + - run: go version + - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Test - run: make test \ No newline at end of file + run: make test diff --git a/HISTORY.md b/HISTORY.md index 743a05d..57da66d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,12 @@ ## ✒ 历史版本的特性介绍 (Features in old versions) +### v0.5.0 + +> 此版本发布于 2023-11-30 + +* 调整单元测试代码 +* API 进入稳定观察期 + ### v0.4.12 > 此版本发布于 2023-06-12 diff --git a/cache_test.go b/cache_test.go index 9ab4c57..b061db3 100644 --- a/cache_test.go +++ b/cache_test.go @@ -28,27 +28,27 @@ const ( // go test -v -cover -run=^TestCacheType$ func TestCacheType(t *testing.T) { if standard.String() != string(standard) { - t.Errorf("standard.String() %s is wrong", standard.String()) + t.Fatalf("standard.String() %s is wrong", standard.String()) } if lru.String() != string(lru) { - t.Errorf("lru.String() %s is wrong", lru.String()) + t.Fatalf("lru.String() %s is wrong", lru.String()) } if lfu.String() != string(lfu) { - t.Errorf("lfu.String() %s is wrong", lfu.String()) + t.Fatalf("lfu.String() %s is wrong", lfu.String()) } if !standard.IsStandard() { - t.Error("!standard.IsStandard()") + t.Fatal("!standard.IsStandard()") } if !lru.IsLRU() { - t.Error("!standard.IsLRU()") + t.Fatal("!standard.IsLRU()") } if !lfu.IsLFU() { - t.Error("!standard.IsLFU()") + t.Fatal("!standard.IsLFU()") } } @@ -87,82 +87,82 @@ func (tc *testCache) Reset() {} func testCacheGet(t *testing.T, cache Cache) { value, found := cache.Get("key") if found { - t.Errorf("get %+v should be not found", value) + t.Fatalf("get %+v should be not found", value) } cache.Set("key", "value", time.Millisecond) value, found = cache.Get("key") if !found { - t.Error("get should be found") + t.Fatal("get should be found") } if value.(string) != "value" { - t.Errorf("value %+v is wrong", value) + t.Fatalf("value %+v is wrong", value) } time.Sleep(2 * time.Millisecond) value, found = cache.Get("key") if found { - t.Errorf("get %+v should be not found", value) + t.Fatalf("get %+v should be not found", value) } } func testCacheSet(t *testing.T, cache Cache) { value, found := cache.Get("key") if found { - t.Errorf("get %+v should be not found", value) + t.Fatalf("get %+v should be not found", value) } cache.Set("key", "value", time.Millisecond) value, found = cache.Get("key") if !found { - t.Error("get should be found") + t.Fatal("get should be found") } if value.(string) != "value" { - t.Errorf("value %+v is wrong", value) + t.Fatalf("value %+v is wrong", value) } time.Sleep(2 * time.Millisecond) value, found = cache.Get("key") if found { - t.Errorf("get %+v should be not found", value) + t.Fatalf("get %+v should be not found", value) } cache.Set("key", "value", NoTTL) value, found = cache.Get("key") if !found { - t.Error("get should be found") + t.Fatal("get should be found") } if value.(string) != "value" { - t.Errorf("value %+v is wrong", value) + t.Fatalf("value %+v is wrong", value) } time.Sleep(2 * time.Millisecond) value, found = cache.Get("key") if !found { - t.Error("get should be found") + t.Fatal("get should be found") } } func testCacheRemove(t *testing.T, cache Cache) { removedValue := cache.Remove("key") if removedValue != nil { - t.Errorf("removedValue %+v is wrong", removedValue) + t.Fatalf("removedValue %+v is wrong", removedValue) } cache.Set("key", "value", NoTTL) removedValue = cache.Remove("key") if removedValue.(string) != "value" { - t.Errorf("removedValue %+v is wrong", removedValue) + t.Fatalf("removedValue %+v is wrong", removedValue) } cache.Set("key", "value", time.Millisecond) @@ -170,14 +170,14 @@ func testCacheRemove(t *testing.T, cache Cache) { removedValue = cache.Remove("key") if removedValue == nil { - t.Error("removedValue == nil") + t.Fatal("removedValue == nil") } } func testCacheSize(t *testing.T, cache Cache) { size := cache.Size() if size != 0 { - t.Errorf("size %d is wrong", size) + t.Fatalf("size %d is wrong", size) } for i := int64(0); i < maxTestEntries; i++ { @@ -186,14 +186,14 @@ func testCacheSize(t *testing.T, cache Cache) { size = cache.Size() if size != maxTestEntries { - t.Errorf("size %d is wrong", size) + t.Fatalf("size %d is wrong", size) } } func testCacheGC(t *testing.T, cache Cache) { size := cache.Size() if size != 0 { - t.Errorf("size %d is wrong", size) + t.Fatalf("size %d is wrong", size) } for i := int64(0); i < maxTestEntries; i++ { @@ -206,14 +206,14 @@ func testCacheGC(t *testing.T, cache Cache) { size = cache.Size() if size != maxTestEntries { - t.Errorf("size %d is wrong", size) + t.Fatalf("size %d is wrong", size) } cache.GC() size = cache.Size() if size != maxTestEntries { - t.Errorf("size %d is wrong", size) + t.Fatalf("size %d is wrong", size) } time.Sleep(2 * time.Millisecond) @@ -222,7 +222,7 @@ func testCacheGC(t *testing.T, cache Cache) { size = cache.Size() if size != maxTestEntries/2 { - t.Errorf("size %d is wrong", size) + t.Fatalf("size %d is wrong", size) } } @@ -234,17 +234,17 @@ func testCacheReset(t *testing.T, cache Cache) { for i := int64(0); i < maxTestEntries; i++ { value, found := cache.Get(strconv.FormatInt(i, 10)) if !found { - t.Errorf("get %d should be found", i) + t.Fatalf("get %d should be found", i) } if value.(int64) != i { - t.Errorf("value %+v is wrong", value) + t.Fatalf("value %+v is wrong", value) } } size := cache.Size() if size != maxTestEntries { - t.Errorf("size %d is wrong", size) + t.Fatalf("size %d is wrong", size) } cache.Reset() @@ -252,13 +252,13 @@ func testCacheReset(t *testing.T, cache Cache) { for i := int64(0); i < maxTestEntries; i++ { value, found := cache.Get(strconv.FormatInt(i, 10)) if found { - t.Errorf("get %d, %+v should be not found", i, value) + t.Fatalf("get %d, %+v should be not found", i, value) } } size = cache.Size() if size != 0 { - t.Errorf("size %d is wrong", size) + t.Fatalf("size %d is wrong", size) } } @@ -279,38 +279,38 @@ func TestNewCache(t *testing.T) { sc1, ok := cache.(*standardCache) if !ok { - t.Errorf("cache.(*standardCache) %T not ok", cache) + t.Fatalf("cache.(*standardCache) %T not ok", cache) } if sc1 == nil { - t.Error("sc1 == nil") + t.Fatal("sc1 == nil") } cache = NewCache(WithLRU(16)) sc2, ok := cache.(*lruCache) if !ok { - t.Errorf("cache.(*lruCache) %T not ok", cache) + t.Fatalf("cache.(*lruCache) %T not ok", cache) } if sc2 == nil { - t.Error("sc2 == nil") + t.Fatal("sc2 == nil") } cache = NewCache(WithShardings(64)) sc, ok := cache.(*shardingCache) if !ok { - t.Errorf("cache.(*shardingCache) %T not ok", cache) + t.Fatalf("cache.(*shardingCache) %T not ok", cache) } if sc == nil { - t.Error("sc == nil") + t.Fatal("sc == nil") } defer func() { if r := recover(); r == nil { - t.Error("new should panic") + t.Fatal("new should panic") } }() @@ -323,15 +323,15 @@ func TestNewCacheWithReport(t *testing.T) { sc1, ok := cache.(*reportableCache) if !ok { - t.Errorf("cache.(*reportableCache) %T not ok", cache) + t.Fatalf("cache.(*reportableCache) %T not ok", cache) } if sc1 == nil { - t.Error("sc1 == nil") + t.Fatal("sc1 == nil") } if reporter == nil { - t.Error("reporter == nil") + t.Fatal("reporter == nil") } } @@ -341,7 +341,7 @@ func TestRunGCTask(t *testing.T) { count := cache.currentCount() if count != 0 { - t.Errorf("cache.currentCount() %d is wrong", count) + t.Fatalf("cache.currentCount() %d is wrong", count) } cancel := RunGCTask(cache, 10*time.Millisecond) @@ -350,7 +350,7 @@ func TestRunGCTask(t *testing.T) { count = cache.currentCount() if count != 10 { - t.Errorf("cache.currentCount() %d is wrong", count) + t.Fatalf("cache.currentCount() %d is wrong", count) } time.Sleep(80 * time.Millisecond) @@ -358,13 +358,13 @@ func TestRunGCTask(t *testing.T) { count = cache.currentCount() if count != 18 { - t.Errorf("cache.currentCount() %d is wrong", count) + t.Fatalf("cache.currentCount() %d is wrong", count) } time.Sleep(time.Second) count = cache.currentCount() if count != 18 { - t.Errorf("cache.currentCount() %d is wrong", count) + t.Fatalf("cache.currentCount() %d is wrong", count) } } diff --git a/config_test.go b/config_test.go index 38e61b2..5758796 100644 --- a/config_test.go +++ b/config_test.go @@ -126,6 +126,6 @@ func TestApplyOptions(t *testing.T) { }) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } diff --git a/doc.go b/doc.go index 3210569..2fa3c4e 100644 --- a/doc.go +++ b/doc.go @@ -480,4 +480,4 @@ Package cachego provides an easy way to use foundation for your caching operatio package cachego // import "github.com/FishGoddess/cachego" // Version is the version string representation of cachego. -const Version = "v0.4.12" +const Version = "v0.5.0" diff --git a/entry_test.go b/entry_test.go index 2c07938..dbcec72 100644 --- a/entry_test.go +++ b/entry_test.go @@ -29,43 +29,43 @@ func TestNewEntry(t *testing.T) { e := newEntry("key", "value", 0, now) if e.key != "key" { - t.Errorf("e.key %s is wrong", e.key) + t.Fatalf("e.key %s is wrong", e.key) } if e.value.(string) != "value" { - t.Errorf("e.value %+v is wrong", e.value) + t.Fatalf("e.value %+v is wrong", e.value) } if e.expiration != 0 { - t.Errorf("e.expiration %+v != 0", e.expiration) + t.Fatalf("e.expiration %+v != 0", e.expiration) } if fmt.Sprintf("%p", e.now) != fmt.Sprintf("%p", now) { - t.Errorf("e.now %p is wrong", e.now) + t.Fatalf("e.now %p is wrong", e.now) } e = newEntry("k", "v", time.Second, now) expiration := time.Now().Add(time.Second).UnixNano() if e.key != "k" { - t.Errorf("e.key %s is wrong", e.key) + t.Fatalf("e.key %s is wrong", e.key) } if e.value.(string) != "v" { - t.Errorf("e.value %+v is wrong", e.value) + t.Fatalf("e.value %+v is wrong", e.value) } if e.expiration == 0 { - t.Error("e.expiration == 0") + t.Fatal("e.expiration == 0") } if fmt.Sprintf("%p", e.now) != fmt.Sprintf("%p", now) { - t.Errorf("e.now %p is wrong", e.now) + t.Fatalf("e.now %p is wrong", e.now) } // Keep one us for code running. if expiration < e.expiration || e.expiration < expiration-testDurationGap.Nanoseconds() { - t.Errorf("e.expiration %d != expiration %d", e.expiration, expiration) + t.Fatalf("e.expiration %d != expiration %d", e.expiration, expiration) } } @@ -74,15 +74,15 @@ func TestEntrySetup(t *testing.T) { e := newEntry("key", "value", 0, now) if e.key != "key" { - t.Errorf("e.key %s is wrong", e.key) + t.Fatalf("e.key %s is wrong", e.key) } if e.value.(string) != "value" { - t.Errorf("e.value %+v is wrong", e.value) + t.Fatalf("e.value %+v is wrong", e.value) } if e.expiration != 0 { - t.Errorf("e.expiration %+v != 0", e.expiration) + t.Fatalf("e.expiration %+v != 0", e.expiration) } ee := e @@ -90,24 +90,24 @@ func TestEntrySetup(t *testing.T) { expiration := time.Now().Add(time.Second).UnixNano() if ee != e { - t.Errorf("ee %p != e %p", ee, e) + t.Fatalf("ee %p != e %p", ee, e) } if e.key != "k" { - t.Errorf("e.key %s is wrong", e.key) + t.Fatalf("e.key %s is wrong", e.key) } if e.value.(string) != "v" { - t.Errorf("e.value %+v is wrong", e.value) + t.Fatalf("e.value %+v is wrong", e.value) } if e.expiration == 0 { - t.Error("e.expiration == 0") + t.Fatal("e.expiration == 0") } // Keep one us for code running. if expiration < e.expiration || e.expiration < expiration-testDurationGap.Nanoseconds() { - t.Errorf("e.expiration %d != expiration %d", e.expiration, expiration) + t.Fatalf("e.expiration %d != expiration %d", e.expiration, expiration) } } @@ -116,12 +116,12 @@ func TestEntryExpired(t *testing.T) { e := newEntry("", nil, time.Millisecond, now) if e.expired(0) { - t.Error("e should be unexpired!") + t.Fatal("e should be unexpired!") } time.Sleep(2 * time.Millisecond) if !e.expired(0) { - t.Error("e should be expired!") + t.Fatal("e should be expired!") } } diff --git a/global_test.go b/global_test.go index 9335449..9e4ebad 100644 --- a/global_test.go +++ b/global_test.go @@ -33,7 +33,7 @@ func BenchmarkHash(b *testing.B) { func TestHash(t *testing.T) { hash := hash("test") if hash < 0 { - t.Errorf("hash %d <= 0", hash) + t.Fatalf("hash %d <= 0", hash) } } @@ -43,7 +43,7 @@ func TestNow(t *testing.T) { expect := time.Now().UnixNano() if got > expect || got < expect-testDurationGap.Nanoseconds() { - t.Errorf("got %d != expect %d", got, expect) + t.Fatalf("got %d != expect %d", got, expect) } } @@ -53,17 +53,17 @@ func TestSetMapInitialCap(t *testing.T) { SetMapInitialCap(-2) if mapInitialCap != oldInitialCap { - t.Errorf("mapInitialCap %d is wrong", mapInitialCap) + t.Fatalf("mapInitialCap %d is wrong", mapInitialCap) } SetMapInitialCap(0) if mapInitialCap != oldInitialCap { - t.Errorf("mapInitialCap %d is wrong", mapInitialCap) + t.Fatalf("mapInitialCap %d is wrong", mapInitialCap) } SetMapInitialCap(2) if mapInitialCap != 2 { - t.Errorf("mapInitialCap %d is wrong", mapInitialCap) + t.Fatalf("mapInitialCap %d is wrong", mapInitialCap) } } @@ -73,16 +73,16 @@ func TestSetSliceInitialCap(t *testing.T) { SetSliceInitialCap(-2) if sliceInitialCap != oldInitialCap { - t.Errorf("sliceInitialCap %d is wrong", sliceInitialCap) + t.Fatalf("sliceInitialCap %d is wrong", sliceInitialCap) } SetSliceInitialCap(0) if sliceInitialCap != oldInitialCap { - t.Errorf("sliceInitialCap %d is wrong", sliceInitialCap) + t.Fatalf("sliceInitialCap %d is wrong", sliceInitialCap) } SetSliceInitialCap(2) if sliceInitialCap != 2 { - t.Errorf("sliceInitialCap %d is wrong", sliceInitialCap) + t.Fatalf("sliceInitialCap %d is wrong", sliceInitialCap) } } diff --git a/lfu_test.go b/lfu_test.go index 91fdb8a..51a0de4 100644 --- a/lfu_test.go +++ b/lfu_test.go @@ -43,12 +43,12 @@ func TestLFUCacheEvict(t *testing.T) { evictedValue := cache.Set(data, data, time.Duration(i)*time.Second) if i >= cache.maxEntries && evictedValue == nil { - t.Errorf("i %d >= cache.maxEntries %d && evictedValue == nil", i, cache.maxEntries) + t.Fatalf("i %d >= cache.maxEntries %d && evictedValue == nil", i, cache.maxEntries) } } if cache.Size() != cache.maxEntries { - t.Errorf("cache.Size() %d != cache.maxEntries %d", cache.Size(), cache.maxEntries) + t.Fatalf("cache.Size() %d != cache.maxEntries %d", cache.Size(), cache.maxEntries) } for i := cache.maxEntries*10 - cache.maxEntries; i < cache.maxEntries*10; i++ { @@ -63,7 +63,7 @@ func TestLFUCacheEvict(t *testing.T) { data := strconv.Itoa(i) value, ok := cache.Get(data) if !ok || value.(string) != data { - t.Errorf("!ok %+v || value.(string) %s != data %s", !ok, value.(string), data) + t.Fatalf("!ok %+v || value.(string) %s != data %s", !ok, value.(string), data) } } @@ -74,7 +74,7 @@ func TestLFUCacheEvict(t *testing.T) { data := strconv.Itoa(i) if entry.key != data || entry.value.(string) != data { - t.Errorf("entry.key %s != data %s || entry.value.(string) %s != data %s", entry.key, data, entry.value.(string), data) + t.Fatalf("entry.key %s != data %s || entry.value.(string) %s != data %s", entry.key, data, entry.value.(string), data) } i++ @@ -110,7 +110,7 @@ func TestLFUCacheEvictSimulate(t *testing.T) { i, err := strconv.ParseInt(key, 10, 64) if err != nil { - t.Error(err) + t.Fatal(err) } counts[i].key = key @@ -144,7 +144,7 @@ func TestLFUCacheEvictSimulate(t *testing.T) { // Count doesn't equal means something wrong happens. if count.count != counts[i].count { - t.Errorf("evictedValue.(string) %s != counts[i].key %s", evictedValue.(string), counts[i].key) + t.Fatalf("evictedValue.(string) %s != counts[i].key %s", evictedValue.(string), counts[i].key) } found = true @@ -152,7 +152,7 @@ func TestLFUCacheEvictSimulate(t *testing.T) { } if !found { - t.Errorf("evictedValue %s not found in counts %+v", evictedValue.(string), counts) + t.Fatalf("evictedValue %s not found in counts %+v", evictedValue.(string), counts) } } } @@ -162,11 +162,11 @@ func TestLFUCacheEvictSimulate(t *testing.T) { item := cache.itemHeap.Pop() if item.Value.(*entry).key != expect[index] { - t.Errorf("item.Value.(*entry).key %s != expect[index] %s", item.Value.(*entry).key, expect[index]) + t.Fatalf("item.Value.(*entry).key %s != expect[index] %s", item.Value.(*entry).key, expect[index]) } if item.Weight() != uint64(maxKeys+index) { - t.Errorf("item.Weight() %d != uint64(maxKeys + index) %d", item.Weight(), uint64(maxKeys+index)) + t.Fatalf("item.Weight() %d != uint64(maxKeys + index) %d", item.Weight(), uint64(maxKeys+index)) } index++ diff --git a/load_test.go b/load_test.go index a3e424f..6275f01 100644 --- a/load_test.go +++ b/load_test.go @@ -71,22 +71,22 @@ func TestNewLoader(t *testing.T) { loader1, ok := l.(*loader) if !ok { - t.Errorf("l.(*loader) %T not ok", l) + t.Fatalf("l.(*loader) %T not ok", l) } if loader1.group != nil { - t.Errorf("loader1.group %+v != nil", loader1.group) + t.Fatalf("loader1.group %+v != nil", loader1.group) } l = NewLoader(nil, true) loader2, ok := l.(*loader) if !ok { - t.Errorf("l.(*loader) %T not ok", l) + t.Fatalf("l.(*loader) %T not ok", l) } if loader2.group == nil { - t.Error("loader2.group == nil") + t.Fatal("loader2.group == nil") } } @@ -104,16 +104,16 @@ func TestLoaderLoad(t *testing.T) { }) if err != nil { - t.Error(err) + t.Fatal(err) } if value.(string) != str { - t.Errorf("value.(string) %s != str %s", value.(string), str) + t.Fatalf("value.(string) %s != str %s", value.(string), str) } } if loadCount != 100 { - t.Errorf("loadCount %d != 100", loadCount) + t.Fatalf("loadCount %d != 100", loadCount) } cache = newTestLoadCache(true) @@ -135,13 +135,13 @@ func TestLoaderLoad(t *testing.T) { }) if err != nil { - t.Error(err) + t.Fatal(err) } }(i) } wg.Wait() if loadCount != 1 { - t.Errorf("loadCount %d != 1", loadCount) + t.Fatalf("loadCount %d != 1", loadCount) } } diff --git a/lru_test.go b/lru_test.go index f4a4617..aa9dd82 100644 --- a/lru_test.go +++ b/lru_test.go @@ -43,19 +43,19 @@ func TestLRUCacheEvict(t *testing.T) { evictedValue := cache.Set(data, data, time.Duration(i)*time.Second) if i >= cache.maxEntries && evictedValue == nil { - t.Errorf("i %d >= cache.maxEntries %d && evictedValue == nil", i, cache.maxEntries) + t.Fatalf("i %d >= cache.maxEntries %d && evictedValue == nil", i, cache.maxEntries) } } if cache.Size() != cache.maxEntries { - t.Errorf("cache.Size() %d != cache.maxEntries %d", cache.Size(), cache.maxEntries) + t.Fatalf("cache.Size() %d != cache.maxEntries %d", cache.Size(), cache.maxEntries) } for i := cache.maxEntries*10 - cache.maxEntries; i < cache.maxEntries*10; i++ { data := strconv.Itoa(i) value, ok := cache.Get(data) if !ok || value.(string) != data { - t.Errorf("!ok %+v || value.(string) %s != data %s", !ok, value.(string), data) + t.Fatalf("!ok %+v || value.(string) %s != data %s", !ok, value.(string), data) } } @@ -66,7 +66,7 @@ func TestLRUCacheEvict(t *testing.T) { data := strconv.Itoa(i) if entry.key != data || entry.value.(string) != data { - t.Errorf("entry.key %s != data %s || entry.value.(string) %s != data %s", entry.key, data, entry.value.(string), data) + t.Fatalf("entry.key %s != data %s || entry.value.(string) %s != data %s", entry.key, data, entry.value.(string), data) } element = element.Prev() @@ -124,7 +124,7 @@ func TestLRUCacheEvictSimulate(t *testing.T) { expect := strings.Join(expectKeys, "") if strings.Compare(got.String(), expect) != 0 { - t.Errorf("got %s != expect %s", got.String(), expect) + t.Fatalf("got %s != expect %s", got.String(), expect) } for i := 0; i < maxTestEntries; i++ { @@ -132,7 +132,7 @@ func TestLRUCacheEvictSimulate(t *testing.T) { evictedValue := cache.Set(data, data, NoTTL) if evictedValue.(string) != expectKeys[i] { - t.Errorf("evictedValue.(string) %s != expectKeys[i] %s", evictedValue.(string), expectKeys[i]) + t.Fatalf("evictedValue.(string) %s != expectKeys[i] %s", evictedValue.(string), expectKeys[i]) } } } diff --git a/option_test.go b/option_test.go index 610a577..5417b65 100644 --- a/option_test.go +++ b/option_test.go @@ -26,7 +26,7 @@ func TestWithCacheName(t *testing.T) { WithCacheName("-").applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -37,7 +37,7 @@ func TestWithLRU(t *testing.T) { WithLRU(666).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -48,7 +48,7 @@ func TestWithLFU(t *testing.T) { WithLFU(999).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -59,7 +59,7 @@ func TestWithShardings(t *testing.T) { WithShardings(1024).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -70,7 +70,7 @@ func TestWithDisableSingleflight(t *testing.T) { WithDisableSingleflight().applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -81,7 +81,7 @@ func TestWithGC(t *testing.T) { WithGC(1024).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -92,7 +92,7 @@ func TestWithMaxScans(t *testing.T) { WithMaxScans(1024).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -103,7 +103,7 @@ func TestWithMaxEntries(t *testing.T) { WithMaxEntries(1024).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -118,7 +118,7 @@ func TestWithNow(t *testing.T) { WithNow(now).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -133,7 +133,7 @@ func TestWithHash(t *testing.T) { WithHash(hash).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -144,7 +144,7 @@ func TestWithRecordMissed(t *testing.T) { WithRecordMissed(true).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -155,7 +155,7 @@ func TestWithRecordHit(t *testing.T) { WithRecordHit(true).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -166,7 +166,7 @@ func TestWithRecordGC(t *testing.T) { WithRecordGC(true).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -177,7 +177,7 @@ func TestWithRecordLoad(t *testing.T) { WithRecordLoad(true).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -190,7 +190,7 @@ func TestWithReportMissed(t *testing.T) { WithReportMissed(reportMissed).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -203,7 +203,7 @@ func TestWithReportHit(t *testing.T) { WithReportHit(reportHit).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -216,7 +216,7 @@ func TestWithReportGC(t *testing.T) { WithReportGC(reportGC).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } @@ -229,6 +229,6 @@ func TestWithReportLoad(t *testing.T) { WithReportLoad(reportLoad).applyTo(got) if !isConfigEquals(got, expect) { - t.Errorf("got %+v != expect %+v", got, expect) + t.Fatalf("got %+v != expect %+v", got, expect) } } diff --git a/pkg/clock/clock_test.go b/pkg/clock/clock_test.go index 95ded64..f44b95e 100644 --- a/pkg/clock/clock_test.go +++ b/pkg/clock/clock_test.go @@ -53,7 +53,7 @@ func TestNew(t *testing.T) { for i := 0; i < 100; i++ { if clocks[i] != clock { - t.Errorf("clocks[i] %p != clock %p", clocks[i], clock) + t.Fatalf("clocks[i] %p != clock %p", clocks[i], clock) } } } @@ -68,7 +68,7 @@ func TestClock(t *testing.T) { expect := time.Now().UnixNano() if math.Abs(float64(expect-now)) > float64(duration)*1.5 { - t.Errorf("now %d is wrong with expect %d", now, expect) + t.Fatalf("now %d is wrong with expect %d", now, expect) } time.Sleep(time.Duration(rand.Int63n(int64(duration)))) diff --git a/pkg/heap/heap_test.go b/pkg/heap/heap_test.go index 3b7cc44..f496fcd 100644 --- a/pkg/heap/heap_test.go +++ b/pkg/heap/heap_test.go @@ -39,42 +39,42 @@ func TestItem(t *testing.T) { item1 := heap.Push(1, 11) if item1.index != 0 { - t.Errorf("item1.index %d is wrong", item1.index) + t.Fatalf("item1.index %d is wrong", item1.index) } item2 := heap.Push(2, 22) if item2.index != 1 { - t.Errorf("item2.index %d is wrong", item2.index) + t.Fatalf("item2.index %d is wrong", item2.index) } item3 := heap.Push(3, 33) if item3.index != 2 { - t.Errorf("item3.index %d is wrong", item3.index) + t.Fatalf("item3.index %d is wrong", item3.index) } if item1.Weight() != 1 || item1.Value.(int) != 11 { - t.Errorf("item1.Weight() %d is wrong || item1.Value.(int) %d is wrong", item1.Weight(), item1.Value.(int)) + t.Fatalf("item1.Weight() %d is wrong || item1.Value.(int) %d is wrong", item1.Weight(), item1.Value.(int)) } if item2.Weight() != 2 || item2.Value.(int) != 22 { - t.Errorf("item2.Weight() %d is wrong || item2.Value.(int) %d is wrong", item2.Weight(), item2.Value.(int)) + t.Fatalf("item2.Weight() %d is wrong || item2.Value.(int) %d is wrong", item2.Weight(), item2.Value.(int)) } if item3.Weight() != 3 || item3.Value.(int) != 33 { - t.Errorf("item3.Weight() %d is wrong || item3.Value.(int) %d is wrong", item3.Weight(), item3.Value.(int)) + t.Fatalf("item3.Weight() %d is wrong || item3.Value.(int) %d is wrong", item3.Weight(), item3.Value.(int)) } item1.Adjust(111) if item1.Weight() != 111 || item1.index != 1 { - t.Errorf("item1.Weight() %d is wrong || item1.index %d is wrong", item1.Weight(), item1.index) + t.Fatalf("item1.Weight() %d is wrong || item1.index %d is wrong", item1.Weight(), item1.index) } if item2.index != 0 { - t.Errorf("item2.index %d is wrong", item2.index) + t.Fatalf("item2.index %d is wrong", item2.index) } if item3.index != 2 { - t.Errorf("item3.index %d is wrong", item3.index) + t.Fatalf("item3.index %d is wrong", item3.index) } item2.Adjust(222) @@ -83,7 +83,7 @@ func TestItem(t *testing.T) { item3.Adjust(weight + 1) if item3.Weight() != 0 { - t.Errorf("item3.Weight() %d is wrong", item3.Weight()) + t.Fatalf("item3.Weight() %d is wrong", item3.Weight()) } expect := []int{33, 11, 22} @@ -92,7 +92,7 @@ func TestItem(t *testing.T) { for heap.Size() > 0 { num := heap.Pop().Value.(int) if num != expect[index] { - t.Errorf("num %d != expect[%d] %d", num, index, expect[index]) + t.Fatalf("num %d != expect[%d] %d", num, index, expect[index]) } index++ @@ -102,7 +102,7 @@ func TestItem(t *testing.T) { for i := uint64(1); i <= 3; i++ { item1.weight = item1.weight + 1 if item1.Weight() != i-1 { - t.Errorf("item1.Weight() %d != (i %d - 1)", item1.Weight(), i) + t.Fatalf("item1.Weight() %d != (i %d - 1)", item1.Weight(), i) } } } @@ -118,7 +118,7 @@ func TestHeap(t *testing.T) { } if heap.Size() != len(data) { - t.Errorf("heap.Size() %d != len(data) %d", heap.Size(), len(data)) + t.Fatalf("heap.Size() %d != len(data) %d", heap.Size(), len(data)) } sort.Ints(data) @@ -128,14 +128,14 @@ func TestHeap(t *testing.T) { for heap.Size() > 0 { num := heap.Pop().Value.(int) if num != data[index] { - t.Errorf("num %d != data[%d] %d", num, index, data[index]) + t.Fatalf("num %d != data[%d] %d", num, index, data[index]) } index++ } if heap.Size() != 0 { - t.Errorf("heap.Size() %d is wrong", heap.Size()) + t.Fatalf("heap.Size() %d is wrong", heap.Size()) } rand.Shuffle(len(data), func(i, j int) { @@ -149,26 +149,26 @@ func TestHeap(t *testing.T) { } if heap.Size() != len(data) { - t.Errorf("heap.Size() %d != len(data) %d", heap.Size(), len(data)) + t.Fatalf("heap.Size() %d != len(data) %d", heap.Size(), len(data)) } if len(items) != len(data) { - t.Errorf("len(items) %d != len(data) %d", len(items), len(data)) + t.Fatalf("len(items) %d != len(data) %d", len(items), len(data)) } for i, num := range data { value := heap.Remove(items[i]) if value.(int) != num { - t.Errorf("value.(int) %d != num %d", value.(int), num) + t.Fatalf("value.(int) %d != num %d", value.(int), num) } } if heap.Size() != 0 { - t.Errorf("heap.Size() %d is wrong", heap.Size()) + t.Fatalf("heap.Size() %d is wrong", heap.Size()) } item := &Item{heap: heap, index: poppedIndex, Value: 123} if value := heap.Remove(item); value.(int) != 123 { - t.Errorf("value.(int) %d is wrong", value.(int)) + t.Fatalf("value.(int) %d is wrong", value.(int)) } } diff --git a/pkg/singleflight/singleflight_test.go b/pkg/singleflight/singleflight_test.go index 8ed23cf..0367194 100644 --- a/pkg/singleflight/singleflight_test.go +++ b/pkg/singleflight/singleflight_test.go @@ -42,12 +42,12 @@ func testGroupCall(t *testing.T, group *Group, concurrency int) { }) if err != nil { - t.Error(err) + t.Fatal(err) } r := atomic.LoadInt64(&rightResult) if result != r { - t.Errorf("result %d != rightResult %d", result, r) + t.Fatalf("result %d != rightResult %d", result, r) } }(int64(i)) } @@ -96,21 +96,21 @@ func TestGroupDelete(t *testing.T) { call := group.calls["key"] if call.deleted { - t.Error("call.deleted is wrong") + t.Fatal("call.deleted is wrong") } group.Delete("key") if !call.deleted { - t.Error("call.deleted is wrong") + t.Fatal("call.deleted is wrong") } if _, ok := group.calls["key"]; ok { - t.Error("group.calls[\"key\"] is ok") + t.Fatal("group.calls[\"key\"] is ok") } if len(group.calls) != 0 { - t.Errorf("len(group.calls) %d is wrong", len(group.calls)) + t.Fatalf("len(group.calls) %d is wrong", len(group.calls)) } } @@ -139,7 +139,7 @@ func TestGroupReset(t *testing.T) { call := group.calls[key] if call.deleted { - t.Errorf("key %s call.deleted is wrong", key) + t.Fatalf("key %s call.deleted is wrong", key) } calls = append(calls, call) @@ -149,16 +149,16 @@ func TestGroupReset(t *testing.T) { for i, call := range calls { if !call.deleted { - t.Errorf("i %d call.deleted is wrong", i) + t.Fatalf("i %d call.deleted is wrong", i) } key := strconv.Itoa(i) if _, ok := group.calls[key]; ok { - t.Errorf("group.calls[%s] is ok", key) + t.Fatalf("group.calls[%s] is ok", key) } } if len(group.calls) != 0 { - t.Errorf("len(group.calls) %d is wrong", len(group.calls)) + t.Fatalf("len(group.calls) %d is wrong", len(group.calls)) } } diff --git a/pkg/task/task_test.go b/pkg/task/task_test.go index a348b3c..c074c04 100644 --- a/pkg/task/task_test.go +++ b/pkg/task/task_test.go @@ -39,11 +39,11 @@ func TestTickerTaskRun(t *testing.T) { beforeFn := func(ctx context.Context) { value, ok := ctx.Value(before.key).(string) if !ok { - t.Errorf("ctx.Value(before.key).(string) %+v failed", ctx.Value(before.key)) + t.Fatalf("ctx.Value(before.key).(string) %+v failed", ctx.Value(before.key)) } if value != before.value { - t.Errorf("value %s != before.value %s", value, before.value) + t.Fatalf("value %s != before.value %s", value, before.value) } result.WriteString(value) @@ -52,11 +52,11 @@ func TestTickerTaskRun(t *testing.T) { mainFn := func(ctx context.Context) { value, ok := ctx.Value(fn.key).(string) if !ok { - t.Errorf("ctx.Value(fn.key).(string) %+v failed", ctx.Value(fn.key)) + t.Fatalf("ctx.Value(fn.key).(string) %+v failed", ctx.Value(fn.key)) } if value != fn.value { - t.Errorf("value %s != fn.value %s", value, fn.value) + t.Fatalf("value %s != fn.value %s", value, fn.value) } atomic.AddInt64(&loop, 1) @@ -66,11 +66,11 @@ func TestTickerTaskRun(t *testing.T) { afterFn := func(ctx context.Context) { value, ok := ctx.Value(after.key).(string) if !ok { - t.Errorf("ctx.Value(after.key).(string) %+v failed", ctx.Value(after.key)) + t.Fatalf("ctx.Value(after.key).(string) %+v failed", ctx.Value(after.key)) } if value != after.value { - t.Errorf("value %s != after.value %s", value, after.value) + t.Fatalf("value %s != after.value %s", value, after.value) } result.WriteString(value) @@ -96,6 +96,6 @@ func TestTickerTaskRun(t *testing.T) { expect.WriteString(after.value) if result.String() != expect.String() { - t.Errorf("result %s != expect %s", result.String(), expect.String()) + t.Fatalf("result %s != expect %s", result.String(), expect.String()) } } diff --git a/report_test.go b/report_test.go index 6151d4c..7f73ba7 100644 --- a/report_test.go +++ b/report_test.go @@ -53,11 +53,11 @@ func TestReportableCacheReportMissed(t *testing.T) { checked := false cache.reportMissed = func(reporter *Reporter, key string) { if key == "key" { - t.Error("key == \"key\"") + t.Fatal("key == \"key\"") } if key != "missed" { - t.Errorf("key %s != \"missed\"", key) + t.Fatalf("key %s != \"missed\"", key) } checked = true @@ -67,16 +67,16 @@ func TestReportableCacheReportMissed(t *testing.T) { cache.Get("missed") if !checked { - t.Error("reportMissed not checked") + t.Fatal("reportMissed not checked") } if reporter.CountMissed() != 1 { - t.Errorf("CountMissed %d is wrong", reporter.CountMissed()) + t.Fatalf("CountMissed %d is wrong", reporter.CountMissed()) } missedRate := reporter.MissedRate() if missedRate < 0.499 || missedRate > 0.501 { - t.Errorf("missedRate %.3f is wrong", missedRate) + t.Fatalf("missedRate %.3f is wrong", missedRate) } } @@ -88,15 +88,15 @@ func TestReportableCacheReportHit(t *testing.T) { checked := false cache.reportHit = func(reporter *Reporter, key string, value interface{}) { if key == "missed" { - t.Error("key == \"missed\"") + t.Fatal("key == \"missed\"") } if key != "key" { - t.Errorf("key %s != \"key\"", key) + t.Fatalf("key %s != \"key\"", key) } if value.(int) != 666 { - t.Errorf("value.(int) %d is wrong", value.(int)) + t.Fatalf("value.(int) %d is wrong", value.(int)) } checked = true @@ -106,16 +106,16 @@ func TestReportableCacheReportHit(t *testing.T) { cache.Get("missed") if !checked { - t.Error("reportHit not checked") + t.Fatal("reportHit not checked") } if reporter.CountHit() != 1 { - t.Errorf("CountHit %d is wrong", reporter.CountHit()) + t.Fatalf("CountHit %d is wrong", reporter.CountHit()) } hitRate := reporter.HitRate() if hitRate < 0.499 || hitRate > 0.501 { - t.Errorf("hitRate %.3f is wrong", hitRate) + t.Fatalf("hitRate %.3f is wrong", hitRate) } } @@ -132,11 +132,11 @@ func TestReportableCacheReportGC(t *testing.T) { checked := false cache.reportGC = func(reporter *Reporter, cost time.Duration, cleans int) { if cost <= 0 { - t.Errorf("cost %d <= 0", cost) + t.Fatalf("cost %d <= 0", cost) } if cleans != 3 { - t.Errorf("cleans %d is wrong", cleans) + t.Fatalf("cleans %d is wrong", cleans) } gcCount++ @@ -147,15 +147,15 @@ func TestReportableCacheReportGC(t *testing.T) { cleans := cache.GC() if cleans != 3 { - t.Errorf("cleans %d is wrong", cleans) + t.Fatalf("cleans %d is wrong", cleans) } if !checked { - t.Error("reportHit not checked") + t.Fatal("reportHit not checked") } if reporter.CountGC() != gcCount { - t.Errorf("CountGC %d is wrong", reporter.CountGC()) + t.Fatalf("CountGC %d is wrong", reporter.CountGC()) } } @@ -167,19 +167,19 @@ func TestReportableCacheReportLoad(t *testing.T) { checked := false cache.reportLoad = func(reporter *Reporter, key string, value interface{}, ttl time.Duration, err error) { if key != "load" { - t.Errorf("key %s is wrong", key) + t.Fatalf("key %s is wrong", key) } if value.(int) != 999 { - t.Errorf("value.(int) %d is wrong", value.(int)) + t.Fatalf("value.(int) %d is wrong", value.(int)) } if ttl != time.Second { - t.Errorf("ttl %s is wrong", ttl) + t.Fatalf("ttl %s is wrong", ttl) } if err != io.EOF { - t.Errorf("err %+v is wrong", err) + t.Fatalf("err %+v is wrong", err) } loadCount++ @@ -191,19 +191,19 @@ func TestReportableCacheReportLoad(t *testing.T) { }) if value.(int) != 999 { - t.Errorf("value.(int) %d is wrong", value.(int)) + t.Fatalf("value.(int) %d is wrong", value.(int)) } if err != io.EOF { - t.Errorf("err %+v is wrong", err) + t.Fatalf("err %+v is wrong", err) } if !checked { - t.Error("reportLoad not checked") + t.Fatal("reportLoad not checked") } if reporter.CountLoad() != loadCount { - t.Errorf("CountLoad %d is wrong", reporter.CountLoad()) + t.Fatalf("CountLoad %d is wrong", reporter.CountLoad()) } } @@ -211,11 +211,11 @@ func TestReportableCacheReportLoad(t *testing.T) { func TestReporterCacheName(t *testing.T) { _, reporter := newTestReportableCache() if reporter.CacheName() != reporter.conf.cacheName { - t.Errorf("CacheName %s is wrong compared with conf", reporter.CacheName()) + t.Fatalf("CacheName %s is wrong compared with conf", reporter.CacheName()) } if reporter.CacheName() != testCacheName { - t.Errorf("CacheName %s is wrong", reporter.CacheName()) + t.Fatalf("CacheName %s is wrong", reporter.CacheName()) } } @@ -223,11 +223,11 @@ func TestReporterCacheName(t *testing.T) { func TestReporterCacheType(t *testing.T) { _, reporter := newTestReportableCache() if reporter.CacheType() != reporter.conf.cacheType { - t.Errorf("CacheType %s is wrong compared with conf", reporter.CacheType()) + t.Fatalf("CacheType %s is wrong compared with conf", reporter.CacheType()) } if reporter.CacheType() != testCacheType { - t.Errorf("CacheType %s is wrong", reporter.CacheType()) + t.Fatalf("CacheType %s is wrong", reporter.CacheType()) } } @@ -235,11 +235,11 @@ func TestReporterCacheType(t *testing.T) { func TestReporterCacheShardings(t *testing.T) { _, reporter := newTestReportableCache() if reporter.CacheShardings() != reporter.conf.shardings { - t.Errorf("CacheShardings %d is wrong compared with conf", reporter.CacheShardings()) + t.Fatalf("CacheShardings %d is wrong compared with conf", reporter.CacheShardings()) } if reporter.CacheShardings() != testCacheShardings { - t.Errorf("CacheShardings %d is wrong", reporter.CacheShardings()) + t.Fatalf("CacheShardings %d is wrong", reporter.CacheShardings()) } } @@ -247,11 +247,11 @@ func TestReporterCacheShardings(t *testing.T) { func TestReporterCacheGC(t *testing.T) { _, reporter := newTestReportableCache() if reporter.CacheGC() != reporter.conf.gcDuration { - t.Errorf("CacheGC %d is wrong compared with conf", reporter.CacheGC()) + t.Fatalf("CacheGC %d is wrong compared with conf", reporter.CacheGC()) } if reporter.CacheGC() != testCacheGCDuration { - t.Errorf("CacheGC %d is wrong", reporter.CacheGC()) + t.Fatalf("CacheGC %d is wrong", reporter.CacheGC()) } } @@ -265,13 +265,13 @@ func TestReporterCacheSize(t *testing.T) { cache.Set("key5", 5, time.Second) if reporter.CacheSize() != 5 { - t.Errorf("CacheSize %d is wrong", reporter.CacheSize()) + t.Fatalf("CacheSize %d is wrong", reporter.CacheSize()) } time.Sleep(100 * time.Millisecond) cache.GC() if reporter.CacheSize() != 2 { - t.Errorf("CacheSize %d is wrong", reporter.CacheSize()) + t.Fatalf("CacheSize %d is wrong", reporter.CacheSize()) } } diff --git a/sharding_test.go b/sharding_test.go index 4e7cebc..ad26ac0 100644 --- a/sharding_test.go +++ b/sharding_test.go @@ -39,7 +39,7 @@ func TestShardingCache(t *testing.T) { func TestShardingCacheIndex(t *testing.T) { cache := newTestShardingCache() if len(cache.caches) != testShardings { - t.Errorf("len(cache.caches) %d is wrong", len(cache.caches)) + t.Fatalf("len(cache.caches) %d is wrong", len(cache.caches)) } for i := 0; i < 100; i++ { @@ -49,7 +49,7 @@ func TestShardingCacheIndex(t *testing.T) { for i := range cache.caches { if cache.caches[i].Size() <= 0 { - t.Errorf("cache.caches[i].Size() %d <= 0", cache.caches[i].Size()) + t.Fatalf("cache.caches[i].Size() %d <= 0", cache.caches[i].Size()) } } } diff --git a/standard_test.go b/standard_test.go index 6bac7a6..d9bbfac 100644 --- a/standard_test.go +++ b/standard_test.go @@ -41,11 +41,11 @@ func TestStandardCacheEvict(t *testing.T) { evictedValue := cache.Set(data, data, time.Duration(i)*time.Second) if i >= cache.maxEntries && evictedValue == nil { - t.Errorf("i %d >= cache.maxEntries %d && evictedValue == nil", i, cache.maxEntries) + t.Fatalf("i %d >= cache.maxEntries %d && evictedValue == nil", i, cache.maxEntries) } } if cache.Size() != cache.maxEntries { - t.Errorf("cache.Size() %d != cache.maxEntries %d", cache.Size(), cache.maxEntries) + t.Fatalf("cache.Size() %d != cache.maxEntries %d", cache.Size(), cache.maxEntries) } }