MCPcopy
hub / github.com/CodisLabs/codis / TestRequestChan3

Function TestRequestChan3

pkg/proxy/request_test.go:54–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestRequestChan3(t *testing.T) {
55 var wg sync.WaitGroup
56 var ch = NewRequestChanBuffer(512)
57
58 const n = 1000 * 1000 * 4
59
60 wg.Add(1)
61 go func() {
62 defer wg.Done()
63 for i := 0; i < n; i++ {
64 ch.PushBack(&Request{UnixNano: int64(i)})
65 if i%1024 == 0 {
66 runtime.Gosched()
67 }
68 }
69 }()
70
71 wg.Add(1)
72 go func() {
73 defer wg.Done()
74 for i := 0; i < n; i++ {
75 r, ok := ch.PopFront()
76 assert.Must(ok && r.UnixNano == int64(i))
77 if i%4096 == 0 {
78 runtime.Gosched()
79 }
80 }
81 }()
82
83 wg.Wait()
84
85 go func() {
86 defer ch.Close()
87 time.Sleep(time.Millisecond * 10)
88 }()
89
90 _, ok := ch.PopFront()
91 assert.Must(!ok)
92}
93
94func BenchmarkRequestGoChannel(b *testing.B) {
95 var request = &Request{

Callers

nothing calls this directly

Calls 8

NewRequestChanBufferFunction · 0.85
DoneMethod · 0.80
PopFrontMethod · 0.80
CloseMethod · 0.65
SleepMethod · 0.65
AddMethod · 0.45
PushBackMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected