(t *testing.T)
| 128 | } |
| 129 | |
| 130 | func 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 | |
| 157 | func createTestCache(t *testing.T) *cache.Cache[string, string] { |
| 158 | t.Helper() |
nothing calls this directly
no test coverage detected