MCPcopy Create free account
hub / github.com/allegro/bigcache / TestWriteAndReadParallelSameKeyWithStats

Function TestWriteAndReadParallelSameKeyWithStats

bigcache_test.go:806–837  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

804}
805
806func TestWriteAndReadParallelSameKeyWithStats(t *testing.T) {
807 t.Parallel()
808
809 c := DefaultConfig(0)
810 c.StatsEnabled = true
811
812 cache, _ := New(context.Background(), c)
813 var wg sync.WaitGroup
814 ntest := 1000
815 n := 10
816 wg.Add(n)
817 key := "key"
818 value := blob('a', 1024)
819 for i := 0; i < ntest; i++ {
820 assertEqual(t, nil, cache.Set(key, value))
821 }
822 for j := 0; j < n; j++ {
823 go func() {
824 for i := 0; i < ntest; i++ {
825 v, err := cache.Get(key)
826 assertEqual(t, nil, err)
827 assertEqual(t, value, v)
828 }
829 wg.Done()
830 }()
831 }
832
833 wg.Wait()
834
835 assertEqual(t, Stats{Hits: int64(n * ntest)}, cache.Stats())
836 assertEqual(t, ntest*n, int(cache.KeyMetadata(key).RequestCount))
837}
838
839func TestCacheReset(t *testing.T) {
840 t.Parallel()

Callers

nothing calls this directly

Calls 8

DefaultConfigFunction · 0.85
NewFunction · 0.85
SetMethod · 0.80
StatsMethod · 0.80
KeyMetadataMethod · 0.80
blobFunction · 0.70
assertEqualFunction · 0.70
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…