-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer_uniform_transformer_test.go
63 lines (52 loc) · 1.24 KB
/
layer_uniform_transformer_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package sinoname
import (
"context"
"testing"
"time"
"go.uber.org/goleak"
"golang.org/x/sync/errgroup"
)
func TestUniformBatch(t *testing.T) {
defer goleak.VerifyNone(t)
producer := make(chan MessagePacket, 3)
producer <- MessagePacket{}
producer <- MessagePacket{}
producer <- MessagePacket{}
close(producer)
layer := newUniformLayer(
newTimeoutTransformer("1", 1*time.Microsecond),
newTimeoutTransformer("2", 1*time.Second),
)
sink, err := layer.PumpOut(context.Background(), &errgroup.Group{}, producer)
if err != nil {
t.Fatal(err)
}
for {
<-time.After(2 * time.Second)
if len(sink) != 0 && cap(sink) != len(sink) {
t.Fatal("every two seconds the channel must be full")
}
v1, ok := <-sink
if !ok {
return
}
v2 := <-sink
if v1 == v2 {
t.Fatal("recieved values must be different")
}
}
}
func newUniformLayer(tf ...TransformerFactory) *UniformTransformerLayer {
layer := &UniformTransformerLayer{
transformers: make([]Transformer, len(tf)),
transformerFactories: make([]TransformerFactory, 0),
}
for i, f := range tf {
t, statefull := f(testConfig)
if statefull {
layer.transformerFactories = append(layer.transformerFactories, f)
}
layer.transformers[i] = t
}
return layer
}