MCPcopy Create free account
hub / github.com/eapache/channels / testDistribute

Function testDistribute

channels_test.go:156–200  ·  view source on GitHub ↗
(t *testing.T, dist func(input SimpleOutChannel, outputs ...SimpleInChannel))

Source from the content-addressed store, hash-verified

154}
155
156func testDistribute(t *testing.T, dist func(input SimpleOutChannel, outputs ...SimpleInChannel)) {
157 a := NewNativeChannel(None)
158 b := NewNativeChannel(None)
159
160 dist(a, b)
161
162 testChannelPair(t, "simple distribute", a, b)
163
164 a = NewNativeChannel(None)
165 outputs := []Channel{
166 NewNativeChannel(None),
167 NewNativeChannel(None),
168 NewNativeChannel(None),
169 NewNativeChannel(None),
170 }
171
172 dist(a, outputs[0], outputs[1], outputs[2], outputs[3])
173
174 go func() {
175 for i := 0; i < 1000; i++ {
176 a.In() <- i
177 }
178 a.Close()
179 }()
180
181 received := make([]bool, 1000)
182 for _ = range received {
183 var val interface{}
184 select {
185 case val = <-outputs[0].Out():
186 case val = <-outputs[1].Out():
187 case val = <-outputs[2].Out():
188 case val = <-outputs[3].Out():
189 }
190 if received[val.(int)] {
191 t.Fatal("distribute got value twice", val.(int))
192 }
193 received[val.(int)] = true
194 }
195 for i := range received {
196 if !received[i] {
197 t.Fatal("distribute missed", i)
198 }
199 }
200}
201
202func TestDistribute(t *testing.T) {
203 testDistribute(t, Distribute)

Callers 2

TestDistributeFunction · 0.85
TestWeakDistributeFunction · 0.85

Calls 5

InMethod · 0.95
CloseMethod · 0.95
NewNativeChannelFunction · 0.85
testChannelPairFunction · 0.85
OutMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…