Skip to content

Fix race condition in testHighPriorityTasksGetExecutedBeforeLowPriorityTasks #2012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Tests/SemanticIndexTests/TaskSchedulerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ final class TaskSchedulerTests: XCTestCase {
}
},
validate: { (recordings: [Set<TaskID>]) in
// Check that all high-priority tasks get executed before the low-priority tasks
let highPriorityRecordingSlice = recordings.dropLast(while: {
$0.isEmpty || $0.contains(where: \.isLowPriority)
// Check that all high-priority tasks start executing before the low-priority tasks
let highPriorityRecordingSlice = recordings.prefix(while: {
$0.isEmpty || $0.contains(where: \.isHighPriority)
})
assertAllSatisfy(highPriorityRecordingSlice) { !$0.contains(where: \.isLowPriority) }
let taskIdsInHighPriorityRecordingSlice = Set(highPriorityRecordingSlice.flatMap { $0 })
XCTAssert(
taskIdsInHighPriorityRecordingSlice.isSuperset(of: (0..<10).map(TaskID.highPriority)),
"Low priority task started executing before high-priority task. Recording: \(recordings)"
)

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