Skip to content

Commit 6bc562d

Browse files
authoredMar 17, 2025
Adjust a timing-sensitive TimeLimitTrait test to avoid flakiness in CI (#1029)
This adjusts the `TimeLimitTraitTests.cancelledTestExitsEarly()` test function to make it less sensitive to running on resource-constrained CI systems. ### Motivation: Recently on a few PRs I have seen flaky results from this test which are unrelated to my work. They typically show up as console output such as: ``` ✘ Test "Cancelled tests can exit early (cancellation checking works)" recorded an issue at TimeLimitTraitTests.swift:193:5: Expectation failed: (timeAwaited → 5.108262525 seconds) < (.seconds(5) → 5.0 seconds) ``` This indicates the test is just a little too sensitive to specific timing. ### Modifications: - Lengthen the "full" sleep duration the test would run if it wasn't cancelled, which it is. - Extend the much shorter duration it allows for waiting, to avoid false positives when running on resource-constrained CI systems. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 939737a commit 6bc562d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎Tests/TestingTests/Traits/TimeLimitTraitTests.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,17 @@ struct TimeLimitTraitTests {
184184
await withTaskGroup(of: Void.self) { taskGroup in
185185
taskGroup.addTask {
186186
await Test {
187-
try await Test.Clock.sleep(for: .seconds(60))
187+
try await Test.Clock.sleep(for: .seconds(60) * 60)
188188
}.run()
189189
}
190190
taskGroup.cancelAll()
191191
}
192192
}
193-
#expect(timeAwaited < .seconds(5)) // less than the 60 second sleep
193+
194+
// Expect that the time awaited is significantly less than the duration of
195+
// the sleep above. To avoid flakiness in CI, allow for a somewhat long
196+
// wait, but still much less than the full sleep duration.
197+
#expect(timeAwaited < .seconds(60))
194198
}
195199

196200
@available(_clockAPI, *)

0 commit comments

Comments
 (0)