MCPcopy
hub / github.com/grpc/grpc-go / TestMultipleWriters

Method TestMultipleWriters

internal/buffer/unbounded_test.go:90–121  ·  view source on GitHub ↗

TestMultipleWriters starts multiple writers and one reader goroutine and makes sure that the reader gets all the data written by all writers.

(t *testing.T)

Source from the content-addressed store, hash-verified

88// TestMultipleWriters starts multiple writers and one reader goroutine and
89// makes sure that the reader gets all the data written by all writers.
90func (s) TestMultipleWriters(t *testing.T) {
91 ub := NewUnbounded()
92 reads := []int{}
93
94 var wg sync.WaitGroup
95 wg.Add(1)
96 go func() {
97 defer wg.Done()
98 ch := ub.Get()
99 for i := 0; i < numWriters*numWrites; i++ {
100 r := <-ch
101 reads = append(reads, r.(int))
102 ub.Load()
103 }
104 }()
105
106 wg.Add(numWriters)
107 for i := 0; i < numWriters; i++ {
108 go func(index int) {
109 defer wg.Done()
110 for j := 0; j < numWrites; j++ {
111 ub.Put(index)
112 }
113 }(i)
114 }
115
116 wg.Wait()
117 sort.Ints(reads)
118 if !reflect.DeepEqual(reads, wantReads) {
119 t.Errorf("reads: %#v, wantReads: %#v", reads, wantReads)
120 }
121}
122
123// TestClose closes the buffer and makes sure that nothing is sent after the
124// buffer is closed.

Callers

nothing calls this directly

Calls 8

GetMethod · 0.95
LoadMethod · 0.95
PutMethod · 0.95
WaitMethod · 0.80
NewUnboundedFunction · 0.70
AddMethod · 0.65
ErrorfMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected