-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathroundrobin_test.go
45 lines (36 loc) · 1.04 KB
/
roundrobin_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package simpleflow
import (
"github.com/stretchr/testify/suite"
"testing"
)
type RoundRobinSuite struct {
suite.Suite
}
func TestRoundRobin(t *testing.T) {
s := new(RoundRobinSuite)
suite.Run(t, s)
}
func (s *RoundRobinSuite) TestRoundRobin() {
N := 9
// Generate some data on a channel (source for fan out)
source := make(chan int, N)
LoadChannel(source, generateSeries(N)...)
close(source)
// Round robin the data into two channels, each should have half the data
fanoutSink1 := make(chan int, N)
fanoutSink2 := make(chan int, N)
RoundRobin(source, fanoutSink1, fanoutSink2)
CloseManyWriters(fanoutSink1, fanoutSink2)
fanout1Data := ChannelToSlice(fanoutSink1)
fanout2Data := ChannelToSlice(fanoutSink2)
s.ElementsMatch(fanout1Data, []int{0, 2, 4, 6, 8})
s.ElementsMatch(fanout2Data, []int{1, 3, 5, 7})
}
func (s *RoundRobinSuite) TestRoundRobinEmptyTo() {
N := 9
// Generate some data on a channel (source for fan out)
source := make(chan int, N)
LoadChannel(source, generateSeries(N)...)
close(source)
RoundRobin(source)
}