MCPcopy Create free account
hub / github.com/MertJSX/folderhost / TestCache_ConcurrentAccess

Function TestCache_ConcurrentAccess

test/cache_test.go:130–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128}
129
130func TestCache_ConcurrentAccess(t *testing.T) {
131 cache := createTestCache(t)
132 key := "concurrent-key"
133
134 t.Run("concurrent set and get", func(t *testing.T) {
135 const goroutines = 10
136 done := make(chan bool, goroutines)
137
138 for i := 0; i < goroutines; i++ {
139 go func(idx int) {
140 defer func() { done <- true }()
141
142 value := string(rune('A' + idx))
143 cache.Set(key, value, time.Minute)
144
145 got, ok := cache.Get(key)
146 assert.True(t, ok)
147 assert.NotEmpty(t, got)
148 }(i)
149 }
150
151 for i := 0; i < goroutines; i++ {
152 <-done
153 }
154 })
155}
156
157func createTestCache(t *testing.T) *cache.Cache[string, string] {
158 t.Helper()

Callers

nothing calls this directly

Calls 3

createTestCacheFunction · 0.85
SetMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected