4
4
"context"
5
5
"sync"
6
6
"tape/pkg/infra"
7
- "time"
8
7
9
8
"github.com/hyperledger/fabric-protos-go/peer"
10
9
. "github.com/onsi/ginkgo"
@@ -19,12 +18,12 @@ var _ = Describe("BlockCollector", func() {
19
18
20
19
Context ("Async Commit" , func () {
21
20
It ("should work with threshold 1 and observer 1" , func () {
22
- instance , err := infra .NewBlockCollector (1 , 1 )
23
- Expect (err ).NotTo (HaveOccurred ())
24
-
25
21
block := make (chan * infra.AddressedBlock )
26
22
done := make (chan struct {})
27
- go instance .Start (context .Background (), block , done , 2 , time .Now (), false )
23
+ instance , err := infra .NewBlockCollector (1 , 1 , context .Background (), block , done , 2 , false )
24
+ Expect (err ).NotTo (HaveOccurred ())
25
+
26
+ go instance .Start ()
28
27
29
28
block <- newAddressedBlock (0 , 0 )
30
29
Consistently (done ).ShouldNot (BeClosed ())
@@ -33,12 +32,12 @@ var _ = Describe("BlockCollector", func() {
33
32
})
34
33
35
34
It ("should work with threshold 1 and observer 2" , func () {
36
- instance , err := infra .NewBlockCollector (1 , 2 )
37
- Expect (err ).NotTo (HaveOccurred ())
38
-
39
35
block := make (chan * infra.AddressedBlock )
40
36
done := make (chan struct {})
41
- go instance .Start (context .Background (), block , done , 2 , time .Now (), false )
37
+ instance , err := infra .NewBlockCollector (1 , 2 , context .Background (), block , done , 2 , false )
38
+ Expect (err ).NotTo (HaveOccurred ())
39
+
40
+ go instance .Start ()
42
41
43
42
block <- newAddressedBlock (0 , 0 )
44
43
Consistently (done ).ShouldNot (BeClosed ())
@@ -55,12 +54,12 @@ var _ = Describe("BlockCollector", func() {
55
54
})
56
55
57
56
It ("should work with threshold 4 and observer 4" , func () {
58
- instance , err := infra .NewBlockCollector (4 , 4 )
59
- Expect (err ).NotTo (HaveOccurred ())
60
-
61
57
block := make (chan * infra.AddressedBlock )
62
58
done := make (chan struct {})
63
- go instance .Start (context .Background (), block , done , 2 , time .Now (), false )
59
+ instance , err := infra .NewBlockCollector (4 , 4 , context .Background (), block , done , 2 , false )
60
+ Expect (err ).NotTo (HaveOccurred ())
61
+
62
+ go instance .Start ()
64
63
65
64
block <- newAddressedBlock (0 , 1 )
66
65
Consistently (done ).ShouldNot (BeClosed ())
@@ -82,12 +81,12 @@ var _ = Describe("BlockCollector", func() {
82
81
})
83
82
84
83
It ("should work with threshold 2 and observer 4" , func () {
85
- instance , err := infra .NewBlockCollector (2 , 4 )
86
- Expect (err ).NotTo (HaveOccurred ())
87
-
88
84
block := make (chan * infra.AddressedBlock )
89
85
done := make (chan struct {})
90
- go instance .Start (context .Background (), block , done , 1 , time .Now (), false )
86
+ instance , err := infra .NewBlockCollector (2 , 4 , context .Background (), block , done , 1 , false )
87
+ Expect (err ).NotTo (HaveOccurred ())
88
+
89
+ go instance .Start ()
91
90
92
91
block <- newAddressedBlock (0 , 0 )
93
92
Consistently (done ).ShouldNot (BeClosed ())
@@ -96,12 +95,12 @@ var _ = Describe("BlockCollector", func() {
96
95
})
97
96
98
97
PIt ("should not count tx for repeated block" , func () {
99
- instance , err := infra .NewBlockCollector (1 , 1 )
100
- Expect (err ).NotTo (HaveOccurred ())
101
-
102
98
block := make (chan * infra.AddressedBlock )
103
99
done := make (chan struct {})
104
- go instance .Start (context .Background (), block , done , 2 , time .Now (), false )
100
+ instance , err := infra .NewBlockCollector (1 , 1 , context .Background (), block , done , 2 , false )
101
+ Expect (err ).NotTo (HaveOccurred ())
102
+
103
+ go instance .Start ()
105
104
106
105
block <- newAddressedBlock (0 , 0 )
107
106
Consistently (done ).ShouldNot (BeClosed ())
@@ -113,28 +112,32 @@ var _ = Describe("BlockCollector", func() {
113
112
})
114
113
115
114
It ("should return err when threshold is greater than total" , func () {
116
- instance , err := infra .NewBlockCollector (2 , 1 )
115
+ block := make (chan * infra.AddressedBlock )
116
+ done := make (chan struct {})
117
+ instance , err := infra .NewBlockCollector (2 , 1 , context .Background (), block , done , 2 , false )
117
118
Expect (err ).Should (MatchError ("threshold [2] must be less than or equal to total [1]" ))
118
119
Expect (instance ).Should (BeNil ())
119
120
})
120
121
121
122
It ("should return err when threshold or total is zero" , func () {
122
- instance , err := infra .NewBlockCollector (0 , 1 )
123
+ block := make (chan * infra.AddressedBlock )
124
+ done := make (chan struct {})
125
+ instance , err := infra .NewBlockCollector (0 , 1 , context .Background (), block , done , 2 , false )
123
126
Expect (err ).Should (MatchError ("threshold and total must be greater than zero" ))
124
127
Expect (instance ).Should (BeNil ())
125
128
126
- instance , err = infra .NewBlockCollector (1 , 0 )
129
+ instance , err = infra .NewBlockCollector (1 , 0 , context . Background (), block , done , 2 , false )
127
130
Expect (err ).Should (MatchError ("threshold and total must be greater than zero" ))
128
131
Expect (instance ).Should (BeNil ())
129
132
})
130
133
131
134
It ("Should supports parallel committers" , func () {
132
- instance , err := infra .NewBlockCollector (100 , 100 )
133
- Expect (err ).NotTo (HaveOccurred ())
134
-
135
135
block := make (chan * infra.AddressedBlock )
136
136
done := make (chan struct {})
137
- go instance .Start (context .Background (), block , done , 1 , time .Now (), false )
137
+ instance , err := infra .NewBlockCollector (100 , 100 , context .Background (), block , done , 1 , false )
138
+ Expect (err ).NotTo (HaveOccurred ())
139
+
140
+ go instance .Start ()
138
141
139
142
var wg sync.WaitGroup
140
143
wg .Add (100 )
@@ -149,12 +152,12 @@ var _ = Describe("BlockCollector", func() {
149
152
})
150
153
151
154
It ("Should supports threshold 3 and observer 5 as parallel committers" , func () {
152
- instance , err := infra .NewBlockCollector (3 , 5 )
153
- Expect (err ).NotTo (HaveOccurred ())
154
-
155
155
block := make (chan * infra.AddressedBlock )
156
156
done := make (chan struct {})
157
- go instance .Start (context .Background (), block , done , 10 , time .Now (), false )
157
+ instance , err := infra .NewBlockCollector (3 , 5 , context .Background (), block , done , 10 , false )
158
+ Expect (err ).NotTo (HaveOccurred ())
159
+
160
+ go instance .Start ()
158
161
159
162
for i := 0 ; i < 3 ; i ++ {
160
163
go func (idx int ) {
@@ -167,13 +170,12 @@ var _ = Describe("BlockCollector", func() {
167
170
})
168
171
169
172
It ("Should supports threshold 5 and observer 5 as parallel committers" , func () {
170
- instance , err := infra .NewBlockCollector (5 , 5 )
171
- Expect (err ).NotTo (HaveOccurred ())
172
-
173
173
block := make (chan * infra.AddressedBlock )
174
174
done := make (chan struct {})
175
+ instance , err := infra .NewBlockCollector (5 , 5 , context .Background (), block , done , 10 , false )
176
+ Expect (err ).NotTo (HaveOccurred ())
175
177
176
- go instance .Start (context . Background (), block , done , 10 , time . Now (), false )
178
+ go instance .Start ()
177
179
for i := 0 ; i < 5 ; i ++ {
178
180
go func (idx int ) {
179
181
for j := 0 ; j < 10 ; j ++ {
0 commit comments