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

Function testMultiplex

channels_test.go:71–104  ·  view source on GitHub ↗
(t *testing.T, multi func(output SimpleInChannel, inputs ...SimpleOutChannel))

Source from the content-addressed store, hash-verified

69}
70
71func testMultiplex(t *testing.T, multi func(output SimpleInChannel, inputs ...SimpleOutChannel)) {
72 a := NewNativeChannel(None)
73 b := NewNativeChannel(None)
74
75 multi(b, a)
76
77 testChannelPair(t, "simple multiplex", a, b)
78
79 a = NewNativeChannel(None)
80 inputs := []Channel{
81 NewNativeChannel(None),
82 NewNativeChannel(None),
83 NewNativeChannel(None),
84 NewNativeChannel(None),
85 }
86
87 multi(a, inputs[0], inputs[1], inputs[2], inputs[3])
88
89 go func() {
90 rand.Seed(time.Now().Unix())
91 for i := 0; i < 1000; i++ {
92 inputs[rand.Intn(len(inputs))].In() <- i
93 }
94 for i := range inputs {
95 inputs[i].Close()
96 }
97 }()
98 for i := 0; i < 1000; i++ {
99 val := <-a.Out()
100 if i != val.(int) {
101 t.Fatal("multiplexing expected", i, "but got", val.(int))
102 }
103 }
104}
105
106func TestMultiplex(t *testing.T) {
107 testMultiplex(t, Multiplex)

Callers 2

TestMultiplexFunction · 0.85
TestWeakMultiplexFunction · 0.85

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…