@@ -130,8 +130,11 @@ func TestProvisionerd(t *testing.T) {
130
130
// Ensures tars with "../../../etc/passwd" as the path
131
131
// are not allowed to run, and will fail the job.
132
132
t .Parallel ()
133
- var complete sync.Once
134
- completeChan := make (chan struct {})
133
+ var (
134
+ completeChan = make (chan struct {})
135
+ completeOnce sync.Once
136
+ )
137
+
135
138
closer := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
136
139
return createProvisionerDaemonClient (t , provisionerDaemonTestServer {
137
140
acquireJob : func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error ) {
@@ -150,9 +153,7 @@ func TestProvisionerd(t *testing.T) {
150
153
},
151
154
updateJob : noopUpdateJob ,
152
155
failJob : func (ctx context.Context , job * proto.FailedJob ) (* proto.Empty , error ) {
153
- complete .Do (func () {
154
- close (completeChan )
155
- })
156
+ completeOnce .Do (func () { close (completeChan ) })
156
157
return & proto.Empty {}, nil
157
158
},
158
159
}), nil
@@ -165,8 +166,11 @@ func TestProvisionerd(t *testing.T) {
165
166
166
167
t .Run ("RunningPeriodicUpdate" , func (t * testing.T ) {
167
168
t .Parallel ()
168
- var complete sync.Once
169
- completeChan := make (chan struct {})
169
+ var (
170
+ completeChan = make (chan struct {})
171
+ completeOnce sync.Once
172
+ )
173
+
170
174
closer := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
171
175
return createProvisionerDaemonClient (t , provisionerDaemonTestServer {
172
176
acquireJob : func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error ) {
@@ -184,9 +188,7 @@ func TestProvisionerd(t *testing.T) {
184
188
}, nil
185
189
},
186
190
updateJob : func (ctx context.Context , update * proto.UpdateJobRequest ) (* proto.UpdateJobResponse , error ) {
187
- complete .Do (func () {
188
- close (completeChan )
189
- })
191
+ completeOnce .Do (func () { close (completeChan ) })
190
192
return & proto.UpdateJobResponse {}, nil
191
193
},
192
194
failJob : func (ctx context.Context , job * proto.FailedJob ) (* proto.Empty , error ) {
@@ -212,14 +214,15 @@ func TestProvisionerd(t *testing.T) {
212
214
didLog atomic.Bool
213
215
didAcquireJob atomic.Bool
214
216
didDryRun atomic.Bool
217
+ completeChan = make (chan struct {})
218
+ completeOnce sync.Once
215
219
)
216
- var complete sync.Once
217
- completeChan := make (chan struct {})
220
+
218
221
closer := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
219
222
return createProvisionerDaemonClient (t , provisionerDaemonTestServer {
220
223
acquireJob : func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error ) {
221
224
if didAcquireJob .Load () {
222
- complete .Do (func () {
225
+ completeOnce .Do (func () {
223
226
close (completeChan )
224
227
})
225
228
return & proto.AcquiredJob {}, nil
@@ -315,16 +318,15 @@ func TestProvisionerd(t *testing.T) {
315
318
didComplete atomic.Bool
316
319
didLog atomic.Bool
317
320
didAcquireJob atomic.Bool
321
+ completeChan = make (chan struct {})
322
+ completeOnce sync.Once
318
323
)
319
- var complete sync.Once
320
- completeChan := make (chan struct {})
324
+
321
325
closer := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
322
326
return createProvisionerDaemonClient (t , provisionerDaemonTestServer {
323
327
acquireJob : func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error ) {
324
328
if didAcquireJob .Load () {
325
- complete .Do (func () {
326
- close (completeChan )
327
- })
329
+ completeOnce .Do (func () { close (completeChan ) })
328
330
return & proto.AcquiredJob {}, nil
329
331
}
330
332
didAcquireJob .Store (true )
@@ -386,13 +388,15 @@ func TestProvisionerd(t *testing.T) {
386
388
var (
387
389
didFail atomic.Bool
388
390
didAcquireJob atomic.Bool
391
+ completeChan = make (chan struct {})
392
+ completeOnce sync.Once
389
393
)
390
- completeChan := make ( chan struct {})
394
+
391
395
closer := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
392
396
return createProvisionerDaemonClient (t , provisionerDaemonTestServer {
393
397
acquireJob : func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error ) {
394
398
if didAcquireJob .Load () {
395
- close (completeChan )
399
+ completeOnce . Do ( func () { close (completeChan ) } )
396
400
return & proto.AcquiredJob {}, nil
397
401
}
398
402
didAcquireJob .Store (true )
@@ -585,10 +589,15 @@ func TestProvisionerd(t *testing.T) {
585
589
586
590
t .Run ("ReconnectAndFail" , func (t * testing.T ) {
587
591
t .Parallel ()
588
- var second atomic.Bool
589
- failChan := make (chan struct {})
590
- failedChan := make (chan struct {})
591
- completeChan := make (chan struct {})
592
+ var (
593
+ second atomic.Bool
594
+ failChan = make (chan struct {})
595
+ failOnce sync.Once
596
+ failedChan = make (chan struct {})
597
+ failedOnce sync.Once
598
+ completeChan = make (chan struct {})
599
+ completeOnce sync.Once
600
+ )
592
601
server := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
593
602
client := createProvisionerDaemonClient (t , provisionerDaemonTestServer {
594
603
acquireJob : func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error ) {
@@ -613,10 +622,10 @@ func TestProvisionerd(t *testing.T) {
613
622
},
614
623
failJob : func (ctx context.Context , job * proto.FailedJob ) (* proto.Empty , error ) {
615
624
if second .Load () {
616
- close (completeChan )
625
+ completeOnce . Do ( func () { close (completeChan ) } )
617
626
return & proto.Empty {}, nil
618
627
}
619
- close (failChan )
628
+ failOnce . Do ( func () { close (failChan ) } )
620
629
<- failedChan
621
630
return & proto.Empty {}, nil
622
631
},
@@ -626,7 +635,7 @@ func TestProvisionerd(t *testing.T) {
626
635
<- failChan
627
636
_ = client .DRPCConn ().Close ()
628
637
second .Store (true )
629
- close (failedChan )
638
+ failedOnce . Do ( func () { close (failedChan ) } )
630
639
}()
631
640
}
632
641
return client , nil
@@ -651,18 +660,20 @@ func TestProvisionerd(t *testing.T) {
651
660
652
661
t .Run ("ReconnectAndComplete" , func (t * testing.T ) {
653
662
t .Parallel ()
654
- var completed sync.Once
655
- var second atomic.Bool
656
- failChan := make (chan struct {})
657
- failedChan := make (chan struct {})
658
- completeChan := make (chan struct {})
663
+ var (
664
+ second atomic.Bool
665
+ failChan = make (chan struct {})
666
+ failOnce sync.Once
667
+ failedChan = make (chan struct {})
668
+ failedOnce sync.Once
669
+ completeChan = make (chan struct {})
670
+ completeOnce sync.Once
671
+ )
659
672
server := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
660
673
client := createProvisionerDaemonClient (t , provisionerDaemonTestServer {
661
674
acquireJob : func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error ) {
662
675
if second .Load () {
663
- completed .Do (func () {
664
- close (completeChan )
665
- })
676
+ completeOnce .Do (func () { close (completeChan ) })
666
677
return & proto.AcquiredJob {}, nil
667
678
}
668
679
return & proto.AcquiredJob {
@@ -688,7 +699,7 @@ func TestProvisionerd(t *testing.T) {
688
699
if second .Load () {
689
700
return & proto.Empty {}, nil
690
701
}
691
- close (failChan )
702
+ failOnce . Do ( func () { close (failChan ) } )
692
703
<- failedChan
693
704
return & proto.Empty {}, nil
694
705
},
@@ -698,7 +709,7 @@ func TestProvisionerd(t *testing.T) {
698
709
<- failChan
699
710
_ = client .DRPCConn ().Close ()
700
711
second .Store (true )
701
- close (failedChan )
712
+ failedOnce . Do ( func () { close (failedChan ) } )
702
713
}()
703
714
}
704
715
return client , nil
0 commit comments