Skip to content

Commit c8dd5e4

Browse files
test: Remove background QoS usages (#5779)
Remove usages of DispatchQueues with qos .background as these can cause flaky tests. Also add a linter to check for such usages in unit tests.
1 parent 8619e0f commit c8dd5e4

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Tests/.swiftlint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ parent_config: ../.swiftlint.yml
33
enabled_rules:
44
- test_case_accessibility
55

6+
custom_rules:
7+
avoid_background_qos_for_dispatch_queue:
8+
name: "Avoid background QoS for dispatch queues in tests"
9+
regex: 'qos:\s*\.background'
10+
message: "Avoid background QoS for dispatch queues in tests, as in CI, work on dispatch queues with background QoS can take a long time to run and lead to flaky tests."
11+
severity: error
12+
613
disabled_rules:
714
- force_cast
815
- force_try

Tests/SentryTests/Networking/RateLimits/SentryConcurrentRateLimitsDictionaryTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class SentryConcurrentRateLimitsDictionaryTests: XCTestCase {
3333
}
3434

3535
func testConcurrentReadWrite() {
36-
let queue1 = DispatchQueue(label: "SentryConcurrentRateLimitsStorageTests1", qos: .background, attributes: [.concurrent, .initiallyInactive])
37-
let queue2 = DispatchQueue(label: "SentryConcurrentRateLimitsStorageTests2", qos: .utility, attributes: [.concurrent, .initiallyInactive])
36+
let queue1 = DispatchQueue(label: "SentryConcurrentRateLimitsStorageTests1", attributes: [.concurrent, .initiallyInactive])
37+
let queue2 = DispatchQueue(label: "SentryConcurrentRateLimitsStorageTests2", attributes: [.concurrent, .initiallyInactive])
3838

3939
let group = DispatchGroup()
4040

Tests/SentryTests/TestUtils/Async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import XCTest
44
func delayNonBlocking(timeout: Double = 0.2) {
55
let group = DispatchGroup()
66
group.enter()
7-
let queue = DispatchQueue(label: "delay", qos: .background, attributes: [])
7+
let queue = DispatchQueue(label: "delay")
88

99
queue.asyncAfter(deadline: .now() + timeout) {
1010
group.leave()

0 commit comments

Comments
 (0)