(t *testing.T)
| 188 | } |
| 189 | |
| 190 | func TestParallelSetAndIteration(t *testing.T) { |
| 191 | t.Parallel() |
| 192 | |
| 193 | rand.Seed(0) |
| 194 | |
| 195 | cache, _ := New(context.Background(), Config{ |
| 196 | Shards: 1, |
| 197 | LifeWindow: time.Second, |
| 198 | MaxEntriesInWindow: 100, |
| 199 | MaxEntrySize: 256, |
| 200 | HardMaxCacheSize: 1, |
| 201 | Verbose: true, |
| 202 | }) |
| 203 | |
| 204 | entrySize := 1024 * 100 |
| 205 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) |
| 206 | defer cancel() |
| 207 | |
| 208 | wg := sync.WaitGroup{} |
| 209 | wg.Add(2) |
| 210 | |
| 211 | go func() { |
| 212 | defer func() { |
| 213 | err := recover() |
| 214 | // no panic |
| 215 | assertEqual(t, err, nil) |
| 216 | }() |
| 217 | |
| 218 | defer wg.Done() |
| 219 | |
| 220 | isTimeout := false |
| 221 | |
| 222 | for { |
| 223 | if isTimeout { |
| 224 | break |
| 225 | } |
| 226 | select { |
| 227 | case <-ctx.Done(): |
| 228 | isTimeout = true |
| 229 | default: |
| 230 | err := cache.Set(strconv.Itoa(rand.Intn(100)), blob('a', entrySize)) |
| 231 | noError(t, err) |
| 232 | } |
| 233 | } |
| 234 | }() |
| 235 | |
| 236 | go func() { |
| 237 | defer func() { |
| 238 | err := recover() |
| 239 | // no panic |
| 240 | assertEqual(t, nil, err) |
| 241 | }() |
| 242 | |
| 243 | defer wg.Done() |
| 244 | |
| 245 | isTimeout := false |
| 246 | |
| 247 | for { |
nothing calls this directly
no test coverage detected
searching dependent graphs…