-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_test.go
45 lines (39 loc) · 873 Bytes
/
merge_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 urx
import (
"fmt"
"sync"
"testing"
"time"
)
const count = 2
func TestMerge(t *testing.T) {
one := createChanObs(10, time.Millisecond*50).Map(func(in interface{}) interface{} {
return in.(int) * -1
}).Publish()
two := createChanObs(20, time.Millisecond*25).Publish()
var wg sync.WaitGroup
values := make([][]int, count, count)
wg.Add(count)
for i := 0; i < count; i++ {
s := &values[i]
*s = make([]int, 0, 0)
go func() {
defer wg.Done()
for i := range Merge(one, two).Subscribe().Values() {
*s = append(*s, i.(int))
}
}()
}
wg.Wait()
for i := range values {
for i0 := range values {
if i0 == i {
continue
}
if len(values[i0]) != len(values[i]) || len(values[i0]) != 30 {
fmt.Printf("[%d] %v\n [%d] %v", len(values[i0]), values[i0], len(values[i]), values[i])
panic("non-equal slices")
}
}
}
}