@@ -109,9 +109,6 @@ func TestResourceManagerServiceInbound(t *testing.T) {
109
109
defer closeEchos (echos )
110
110
defer closeRcmgrs (echos )
111
111
112
- ready := make (chan struct {})
113
- echos [0 ].BeforeDone (waitForChannel (ready , time .Minute ))
114
-
115
112
for i := 1 ; i < 5 ; i ++ {
116
113
err := echos [i ].Host .Connect (context .Background (), peer.AddrInfo {ID : echos [0 ].Host .ID ()})
117
114
if err != nil {
@@ -120,9 +117,16 @@ func TestResourceManagerServiceInbound(t *testing.T) {
120
117
time .Sleep (10 * time .Millisecond )
121
118
}
122
119
120
+ ready := make (chan struct {})
121
+ echos [0 ].BeforeDone (waitForChannel (ready , time .Minute ))
122
+
123
+ var eg sync.WaitGroup
124
+ echos [0 ].Done (eg .Done )
125
+
123
126
var once sync.Once
124
127
var wg sync.WaitGroup
125
128
for i := 1 ; i < 5 ; i ++ {
129
+ eg .Add (1 )
126
130
wg .Add (1 )
127
131
go func (i int ) {
128
132
defer wg .Done ()
@@ -137,6 +141,7 @@ func TestResourceManagerServiceInbound(t *testing.T) {
137
141
}(i )
138
142
}
139
143
wg .Wait ()
144
+ eg .Wait ()
140
145
141
146
checkEchoStatus (t , echos [0 ], EchoStatus {
142
147
StreamsIn : 4 ,
@@ -157,11 +162,6 @@ func TestResourceManagerServicePeerInbound(t *testing.T) {
157
162
defer closeEchos (echos )
158
163
defer closeRcmgrs (echos )
159
164
160
- count := new (int32 )
161
- ready := make (chan struct {})
162
- * count = 4
163
- echos [0 ].BeforeDone (waitForBarrier (count , ready , time .Minute ))
164
-
165
165
for i := 1 ; i < 5 ; i ++ {
166
166
err := echos [i ].Host .Connect (context .Background (), peer.AddrInfo {ID : echos [0 ].Host .ID ()})
167
167
if err != nil {
@@ -170,8 +170,14 @@ func TestResourceManagerServicePeerInbound(t *testing.T) {
170
170
time .Sleep (10 * time .Millisecond )
171
171
}
172
172
173
+ echos [0 ].BeforeDone (waitForBarrier (4 , time .Minute ))
174
+
175
+ var eg sync.WaitGroup
176
+ echos [0 ].Done (eg .Done )
177
+
173
178
var wg sync.WaitGroup
174
179
for i := 1 ; i < 5 ; i ++ {
180
+ eg .Add (1 )
175
181
wg .Add (1 )
176
182
go func (i int ) {
177
183
defer wg .Done ()
@@ -183,6 +189,7 @@ func TestResourceManagerServicePeerInbound(t *testing.T) {
183
189
}(i )
184
190
}
185
191
wg .Wait ()
192
+ eg .Wait ()
186
193
187
194
checkEchoStatus (t , echos [0 ], EchoStatus {
188
195
StreamsIn : 4 ,
@@ -191,11 +198,12 @@ func TestResourceManagerServicePeerInbound(t *testing.T) {
191
198
ResourceServiceErrors : 0 ,
192
199
})
193
200
194
- ready = make (chan struct {})
201
+ ready : = make (chan struct {})
195
202
echos [0 ].BeforeDone (waitForChannel (ready , time .Minute ))
196
203
197
204
var once sync.Once
198
205
for i := 0 ; i < 3 ; i ++ {
206
+ eg .Add (1 )
199
207
wg .Add (1 )
200
208
go func () {
201
209
defer wg .Done ()
@@ -210,6 +218,7 @@ func TestResourceManagerServicePeerInbound(t *testing.T) {
210
218
}()
211
219
}
212
220
wg .Wait ()
221
+ eg .Wait ()
213
222
214
223
checkEchoStatus (t , echos [0 ], EchoStatus {
215
224
StreamsIn : 7 ,
@@ -219,9 +228,12 @@ func TestResourceManagerServicePeerInbound(t *testing.T) {
219
228
})
220
229
}
221
230
222
- func waitForBarrier (count * int32 , ready chan struct {}, timeout time.Duration ) func () error {
231
+ func waitForBarrier (count int32 , timeout time.Duration ) func () error {
232
+ ready := make (chan struct {})
233
+ wait := new (int32 )
234
+ * wait = count
223
235
return func () error {
224
- if atomic .AddInt32 (count , - 1 ) == 0 {
236
+ if atomic .AddInt32 (wait , - 1 ) == 0 {
225
237
close (ready )
226
238
}
227
239
0 commit comments