From 42449a820cd77aae54f65faa0e86e6d8744f0ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Tue, 23 Apr 2019 15:06:03 +0300 Subject: [PATCH] store/cache: add more tests --- pkg/store/cache_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/store/cache_test.go b/pkg/store/cache_test.go index 0c3d241668..b33931fd7a 100644 --- a/pkg/store/cache_test.go +++ b/pkg/store/cache_test.go @@ -23,6 +23,28 @@ func TestIndexCacheEdge(t *testing.T) { fits = cache.ensureFits([]byte{42}) testutil.Equals(t, fits, true) + + fits = cache.ensureFits([]byte{}) + testutil.Equals(t, fits, true) + + fits = cache.ensureFits([]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) + testutil.Equals(t, fits, false) + + metrics = prometheus.NewRegistry() + cache, err = newIndexCache(metrics, 0) + testutil.Ok(t, err) + + fits = cache.ensureFits([]byte{42, 24}) + testutil.Equals(t, fits, false) + + fits = cache.ensureFits([]byte{42}) + testutil.Equals(t, fits, false) + + fits = cache.ensureFits([]byte{}) + testutil.Equals(t, fits, true) + + fits = cache.ensureFits([]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) + testutil.Equals(t, fits, false) } // TestIndexCacheSmoke runs the smoke tests for the index cache. @@ -58,4 +80,10 @@ func TestIndexCacheSmoke(t *testing.T) { cache.lru.RemoveOldest() testutil.Equals(t, cache.curSize, uint64(0)) + + cache.setSeries(blid, 1234, []byte{1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1}) + cache.setSeries(blid, 1237, []byte{1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1}) + cache.setSeries(blid, 1235, []byte{1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 5}) + testutil.Equals(t, cache.curSize, uint64(20)) + }