Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99d6d18

Browse files
committed
test: Wrap provisionerd channel closes in sync.Once (#1181)
This caused a few flakes, so figured I'd tackle all of them:https://github.com/coder/coder/runs/6167856950?check_suite_focus=true#step:9:246
1 parent6996ff5 commit99d6d18

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

‎provisionerd/provisionerd_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func TestProvisionerd(t *testing.T) {
8484
t.Run("CloseCancelsJob",func(t*testing.T) {
8585
t.Parallel()
8686
completeChan:=make(chanstruct{})
87+
varcompleted sync.Once
8788
varcloser io.Closer
8889
varcloserMutex sync.Mutex
8990
closerMutex.Lock()
@@ -105,7 +106,9 @@ func TestProvisionerd(t *testing.T) {
105106
},
106107
updateJob:noopUpdateJob,
107108
failJob:func(ctx context.Context,job*proto.FailedJob) (*proto.Empty,error) {
108-
close(completeChan)
109+
completed.Do(func() {
110+
close(completeChan)
111+
})
109112
return&proto.Empty{},nil
110113
},
111114
}),nil
@@ -432,6 +435,8 @@ func TestProvisionerd(t *testing.T) {
432435

433436
t.Run("Shutdown",func(t*testing.T) {
434437
t.Parallel()
438+
varupdated sync.Once
439+
varcompleted sync.Once
435440
updateChan:=make(chanstruct{})
436441
completeChan:=make(chanstruct{})
437442
server:=createProvisionerd(t,func(ctx context.Context) (proto.DRPCProvisionerDaemonClient,error) {
@@ -453,12 +458,16 @@ func TestProvisionerd(t *testing.T) {
453458
updateJob:func(ctx context.Context,update*proto.UpdateJobRequest) (*proto.UpdateJobResponse,error) {
454459
iflen(update.Logs)>0&&update.Logs[0].Source==proto.LogSource_PROVISIONER {
455460
// Close on a log so we know when the job is in progress!
456-
close(updateChan)
461+
updated.Do(func() {
462+
close(updateChan)
463+
})
457464
}
458465
return&proto.UpdateJobResponse{},nil
459466
},
460467
failJob:func(ctx context.Context,job*proto.FailedJob) (*proto.Empty,error) {
461-
close(completeChan)
468+
completed.Do(func() {
469+
close(completeChan)
470+
})
462471
return&proto.Empty{},nil
463472
},
464473
}),nil
@@ -642,6 +651,7 @@ func TestProvisionerd(t *testing.T) {
642651

643652
t.Run("ReconnectAndComplete",func(t*testing.T) {
644653
t.Parallel()
654+
varcompleted sync.Once
645655
varsecond atomic.Bool
646656
failChan:=make(chanstruct{})
647657
failedChan:=make(chanstruct{})
@@ -650,7 +660,9 @@ func TestProvisionerd(t *testing.T) {
650660
client:=createProvisionerDaemonClient(t,provisionerDaemonTestServer{
651661
acquireJob:func(ctx context.Context,_*proto.Empty) (*proto.AcquiredJob,error) {
652662
ifsecond.Load() {
653-
close(completeChan)
663+
completed.Do(func() {
664+
close(completeChan)
665+
})
654666
return&proto.AcquiredJob{},nil
655667
}
656668
return&proto.AcquiredJob{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp