Skip to content

Commit fc0db35

Browse files
authored
Merge pull request #2012 from ahoppen/task-scheduler-test-fix
Fix race condition in `testHighPriorityTasksGetExecutedBeforeLowPriorityTasks`
2 parents 0258d1d + a32be44 commit fc0db35

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Tests/SemanticIndexTests/TaskSchedulerTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ final class TaskSchedulerTests: XCTestCase {
3939
}
4040
},
4141
validate: { (recordings: [Set<TaskID>]) in
42-
// Check that all high-priority tasks get executed before the low-priority tasks
43-
let highPriorityRecordingSlice = recordings.dropLast(while: {
44-
$0.isEmpty || $0.contains(where: \.isLowPriority)
42+
// Check that all high-priority tasks start executing before the low-priority tasks
43+
let highPriorityRecordingSlice = recordings.prefix(while: {
44+
$0.isEmpty || $0.contains(where: \.isHighPriority)
4545
})
46-
assertAllSatisfy(highPriorityRecordingSlice) { !$0.contains(where: \.isLowPriority) }
46+
let taskIdsInHighPriorityRecordingSlice = Set(highPriorityRecordingSlice.flatMap { $0 })
47+
XCTAssert(
48+
taskIdsInHighPriorityRecordingSlice.isSuperset(of: (0..<10).map(TaskID.highPriority)),
49+
"Low priority task started executing before high-priority task. Recording: \(recordings)"
50+
)
4751

4852
// Check that we never have more than the allowed number of low/high priority tasks, respectively
4953
assertAllSatisfy(recordings) { $0.count(where: \.isLowPriority) <= lowPriorityTasks }

0 commit comments

Comments
 (0)