@@ -84,6 +84,7 @@ func TestProvisionerd(t *testing.T) {
84
84
t .Run ("CloseCancelsJob" , func (t * testing.T ) {
85
85
t .Parallel ()
86
86
completeChan := make (chan struct {})
87
+ var completed sync.Once
87
88
var closer io.Closer
88
89
var closerMutex sync.Mutex
89
90
closerMutex .Lock ()
@@ -105,7 +106,9 @@ func TestProvisionerd(t *testing.T) {
105
106
},
106
107
updateJob : noopUpdateJob ,
107
108
failJob : func (ctx context.Context , job * proto.FailedJob ) (* proto.Empty , error ) {
108
- close (completeChan )
109
+ completed .Do (func () {
110
+ close (completeChan )
111
+ })
109
112
return & proto.Empty {}, nil
110
113
},
111
114
}), nil
@@ -432,6 +435,8 @@ func TestProvisionerd(t *testing.T) {
432
435
433
436
t .Run ("Shutdown" , func (t * testing.T ) {
434
437
t .Parallel ()
438
+ var updated sync.Once
439
+ var completed sync.Once
435
440
updateChan := make (chan struct {})
436
441
completeChan := make (chan struct {})
437
442
server := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
@@ -453,12 +458,16 @@ func TestProvisionerd(t *testing.T) {
453
458
updateJob : func (ctx context.Context , update * proto.UpdateJobRequest ) (* proto.UpdateJobResponse , error ) {
454
459
if len (update .Logs ) > 0 && update .Logs [0 ].Source == proto .LogSource_PROVISIONER {
455
460
// Close on a log so we know when the job is in progress!
456
- close (updateChan )
461
+ updated .Do (func () {
462
+ close (updateChan )
463
+ })
457
464
}
458
465
return & proto.UpdateJobResponse {}, nil
459
466
},
460
467
failJob : func (ctx context.Context , job * proto.FailedJob ) (* proto.Empty , error ) {
461
- close (completeChan )
468
+ completed .Do (func () {
469
+ close (completeChan )
470
+ })
462
471
return & proto.Empty {}, nil
463
472
},
464
473
}), nil
@@ -642,6 +651,7 @@ func TestProvisionerd(t *testing.T) {
642
651
643
652
t .Run ("ReconnectAndComplete" , func (t * testing.T ) {
644
653
t .Parallel ()
654
+ var completed sync.Once
645
655
var second atomic.Bool
646
656
failChan := make (chan struct {})
647
657
failedChan := make (chan struct {})
@@ -650,7 +660,9 @@ func TestProvisionerd(t *testing.T) {
650
660
client := createProvisionerDaemonClient (t , provisionerDaemonTestServer {
651
661
acquireJob : func (ctx context.Context , _ * proto.Empty ) (* proto.AcquiredJob , error ) {
652
662
if second .Load () {
653
- close (completeChan )
663
+ completed .Do (func () {
664
+ close (completeChan )
665
+ })
654
666
return & proto.AcquiredJob {}, nil
655
667
}
656
668
return & proto.AcquiredJob {
0 commit comments