Skip to content

Commit

Permalink
Fix race condition in test
Browse files Browse the repository at this point in the history
  • Loading branch information
hlubek committed Jul 11, 2023
1 parent a116b54 commit c54653f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions prunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,17 @@ func TestPipelineRunner_CancelJob_WithQueuedJob(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

var (
startedJobsIDs []string
wait = make(chan struct{})
)
var mx sync.Mutex
var startedJobsIDs []string
var wait = make(chan struct{})

pRunner, err := NewPipelineRunner(ctx, defs, func(j *PipelineJob) taskctl.Runner {
return &test.MockRunner{
OnRun: func(t *task.Task) error {
jobID := t.Variables.Get(taskctl.JobIDVariableName)
mx.Lock()
startedJobsIDs = append(startedJobsIDs, jobID.(string))
mx.Unlock()

// Wait until the job should proceed (wait channel is closed)
<-wait
Expand Down Expand Up @@ -330,8 +331,9 @@ func TestPipelineRunner_CancelJob_WithQueuedJob(t *testing.T) {

assert.Equal(t, true, job2.Tasks.ByName("sleep").Canceled, "job task was marked as canceled")

mx.Lock()
defer mx.Unlock()
assert.Equal(t, []string{job1.ID.String()}, startedJobsIDs, "only job1 was started")

}

func TestPipelineRunner_CancelJob_WithStoppedJob_ShouldNotThrowFatalError(t *testing.T) {
Expand Down

0 comments on commit c54653f

Please sign in to comment.