MCPcopy Create free account
hub / github.com/krau/SaveAny-Bot / TestConcurrencySafety

Function TestConcurrencySafety

pkg/queue/queue_test.go:80–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestConcurrencySafety(t *testing.T) {
81 q := queue.NewTaskQueue[int]()
82 var wg sync.WaitGroup
83 n := 1000
84 // producers
85 wg.Go(func() {
86 for i := range n {
87 q.Add(newTask(fmt.Sprintf("p%d", i)))
88 }
89 })
90 // consumers
91 wg.Go(func() {
92 count := 0
93 for count < n {
94 _, err := q.Get()
95 if err != nil {
96 continue
97 }
98 count++
99 }
100 })
101 wg.Wait()
102}

Callers

nothing calls this directly

Calls 4

newTaskFunction · 0.85
AddMethod · 0.80
GetMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected