Skip to content

Commit

Permalink
test(workflow): eliminate data race
Browse files Browse the repository at this point in the history
  • Loading branch information
hbomb79 committed Jul 20, 2024
1 parent 0389955 commit f8d5ae5
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions tests/integration/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,24 +448,28 @@ func TestWorkflow_Ingestion(t *testing.T) {
return
}

// Give Thea some time to kickoff the transcodes
time.Sleep(1 * time.Second)

// Check transcode service for matching transcodes
transcodes := client.ListActiveTranscodeTasks(t)

// Ensure each target has a transcode for our media
if test.shouldInitiateTranscode {
assert.Len(t, transcodes, len(targetIDs))
targetsExpected := make([]uuid.UUID, 0, len(transcodes))
for _, transcode := range transcodes {
targetsExpected = append(targetsExpected, transcode.TargetId)
assert.Equalf(t, mediaID, transcode.MediaId, "expected all transcodes to belong to the same media ID")
if !assert.EventuallyWithT(t, func(c *assert.CollectT) {
// Check transcode service for matching transcodes
transcodes := client.ListActiveTranscodeTasks(t)

// Ensure each target has a transcode for our media
assert.Len(c, transcodes, len(targetIDs))
targetsExpected := make([]uuid.UUID, 0, len(transcodes))
for _, transcode := range transcodes {
targetsExpected = append(targetsExpected, transcode.TargetId)
assert.Equalf(c, mediaID, transcode.MediaId, "expected all transcodes to belong to the same media ID")
}

assert.ElementsMatchf(c, targetsExpected, targetIDs, "expected a transcode to be started for each of the specified target IDs")
}, 5*time.Second, 1*time.Second, "Transcodes never started") {
return
}

assert.ElementsMatchf(t, targetsExpected, targetIDs, "expected a transcode to be started for each of the specified target IDs")
} else {
assert.Empty(t, transcodes, "expected no transcodes to be initiated by this workflow")
// Ensure no transcodes start
assert.Never(t, func() bool {
return len(client.ListActiveTranscodeTasks(t)) > 0
}, time.Second*5, time.Second*1, "expected no transcodes to be initiated by this workflow")
}

// Poll the media endpoint for this transcode and ensure we see the correct watch target output
Expand Down Expand Up @@ -506,7 +510,7 @@ func TestWorkflow_Ingestion(t *testing.T) {
}

// Cancel the transcodes
for _, transcode := range transcodes {
for _, transcode := range client.ListActiveTranscodeTasks(t) {
t.Logf("Deleting (cancelling) transcode %v", transcode)
resp, err := client.DeleteTranscodeTaskWithResponse(ctx, transcode.Id)
assert.NoError(t, err)
Expand Down

0 comments on commit f8d5ae5

Please sign in to comment.