Skip to content

Commit b358b16

Browse files
committed
Relax the assertion in testHighPriorityTasksGetExecutedBeforeLowPriorityTasks
I just received the following recordings during local test execution: ``` Set([high(1), high(0)]) Set([high(1), high(0), high(2)]) Set([high(2), high(3), high(1), high(0)]) Set([high(2), high(3), high(1)]) Set([high(2), high(3)]) Set([high(2), high(3), high(4)]) Set([high(2), high(3), high(4), high(5)]) Set([high(3), high(4), high(5)]) Set([high(4), high(5)]) Set([high(4), high(5), high(6)]) Set([high(7), high(4), high(5), high(6)]) Set([high(7), high(5), high(6)]) Set([high(7), high(5)]) Set([high(5)]) Set([]) Set([low(0)]) Set([low(0), high(8)]) Set([low(0), high(8), low(1)]) Set([low(0), high(8), low(1), high(9)]) Set([low(0), high(8), low(1)]) Set([low(0), low(1)]) Set([low(1)]) Set([]) ... ``` These recordings didn't satisfy the old assertion because a low-priority task started executing before the last high-priority task. But really what happened is that `low(0)`, `high(8)`, `low(1)`, and `high(9)` were all scheduled simultaneously and `low(0)` just happened to start executing a tiny bit before `high(8)`. To account for these races, relax the assertion to check that all high-priority tasks start executing before the first low-priority task finishes executing.
1 parent 71dfc73 commit b358b16

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Tests/SemanticIndexTests/TaskSchedulerTests.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ final class TaskSchedulerTests: XCTestCase {
3939
}
4040
},
4141
validate: { (recordings: [Set<TaskID>]) in
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)
42+
// Check that all high-priority tasks start executing before the first low-priority task finishes
43+
var startedLowPriorityTasks: Set<TaskID> = []
44+
let highPriorityRecordingSlice = recordings.prefix(while: { recording in
45+
if startedLowPriorityTasks.contains(where: { !recording.contains($0) }) {
46+
return false
47+
}
48+
startedLowPriorityTasks.formUnion(recording.filter(\.isLowPriority))
49+
return true
4550
})
4651
let taskIdsInHighPriorityRecordingSlice = Set(highPriorityRecordingSlice.flatMap { $0 })
4752
XCTAssert(

0 commit comments

Comments
 (0)