(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func TestConcurrentGetOrCreateAndRemoveIf(t *testing.T) { |
| 81 | r := newGroupRegistry[*int]() |
| 82 | const n = 100 |
| 83 | var wg sync.WaitGroup |
| 84 | wg.Add(n * 2) |
| 85 | for i := range n { |
| 86 | v := i |
| 87 | go func() { |
| 88 | defer wg.Done() |
| 89 | r.getOrCreate("k", func() *int { return &v }) |
| 90 | }() |
| 91 | go func() { |
| 92 | defer wg.Done() |
| 93 | r.removeIf("k", func(*int) bool { return true }) |
| 94 | }() |
| 95 | } |
| 96 | wg.Wait() |
| 97 | |
| 98 | // After all goroutines finish, accessing the key must not panic. |
| 99 | require.NotPanics(t, func() { |
| 100 | _, _ = r.get("k") |
| 101 | }) |
| 102 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…