MCPcopy
hub / github.com/fatedier/frp / TestConcurrentGetOrCreateAndRemoveIf

Function TestConcurrentGetOrCreateAndRemoveIf

server/group/registry_test.go:80–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func 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}

Callers

nothing calls this directly

Calls 5

getOrCreateMethod · 0.80
removeIfMethod · 0.80
getMethod · 0.80
AddMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…