MCPcopy Create free account
hub / github.com/dustinxie/lockfree / TestNewQueue

Function TestNewQueue

queue_test.go:25–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestNewQueue(t *testing.T) {
26 req := require.New(t)
27
28 // test 4 threads
29 q := NewQueue()
30 m := NewHashMap()
31 wg := sync.WaitGroup{}
32 wg.Add(4)
33 for i := 0; i < 4; i++ {
34 go func(start, end int) {
35 for i := start; i < end; i++ {
36 q.Enque(i)
37 }
38 for i := start; i < end; i++ {
39 m.Set(q.Deque(), nil)
40 }
41 wg.Done()
42 }(i*10000, (i+1)*10000)
43 }
44 wg.Wait()
45 req.Equal(0, q.Len())
46 req.Nil(q.Deque())
47 req.Equal(40000, m.Len())
48 for i := 0; i < 40000; i++ {
49 v, ok := m.Get(i)
50 req.Nil(v)
51 req.True(ok)
52 }
53}
54
55func BenchmarkLockfreeQueue(b *testing.B) {
56 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 8

EnqueMethod · 0.95
SetMethod · 0.95
DequeMethod · 0.95
LenMethod · 0.95
LenMethod · 0.95
GetMethod · 0.95
NewHashMapFunction · 0.85
NewQueueFunction · 0.70

Tested by

no test coverage detected