Skip to content

Commit 406fb7e

Browse files
authored
Merge pull request #1331 from ahoppen/await-scheduling
Fix a non-deterministic test failure in the task scheduler
2 parents 814f3c5 + 9757181 commit 406fb7e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Tests/SKCoreTests/TaskSchedulerTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ final class TaskSchedulerTests: XCTestCase {
195195
}
196196
)
197197
}
198-
199198
}
200199

201200
// MARK: - Test helpers
@@ -354,8 +353,11 @@ fileprivate extension TaskScheduler<ClosureTaskDescription> {
354353
body,
355354
dependencies: dependencies
356355
)
356+
// Make sure that we call `schedule` outside of the `Task` because the execution order of `Task`s is not guaranteed
357+
// and if we called `schedule` inside `Task`, Swift concurrency can re-order the order that we schedule tasks in.
358+
let queuedTask = await self.schedule(priority: priority, taskDescription)
357359
return Task(priority: priority) {
358-
await self.schedule(priority: priority, taskDescription).waitToFinishPropagatingCancellation()
360+
await queuedTask.waitToFinishPropagatingCancellation()
359361
}
360362
}
361363
}

0 commit comments

Comments
 (0)