Skip to content

Commit 5d238d3

Browse files
test: Use XCTestExpectation for Span (#5849)
Replace the dispatch group with an XCTestExpectation to get a failure message when the wait times out. Contributes to GH-5789
1 parent a3dfd57 commit 5d238d3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Tests/SentryTests/Transaction/SentrySpanTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ class SentrySpanTests: XCTestCase {
603603

604604
func testModifyingExtraFromMultipleThreads() {
605605
let queue = DispatchQueue(label: "SentrySpanTests", qos: .userInteractive, attributes: [.concurrent, .initiallyInactive])
606-
let group = DispatchGroup()
607606

608607
let span = fixture.getSut()
609608

@@ -612,22 +611,27 @@ class SentrySpanTests: XCTestCase {
612611
let innerLoop = 1_000
613612
let outerLoop = 20
614613
let value = fixture.extraValue
614+
615+
let expectation = XCTestExpectation(description: "ModifyingExtraFromMultipleThreads")
616+
expectation.expectedFulfillmentCount = outerLoop
617+
expectation.assertForOverFulfill = true
615618

616619
for i in 0..<outerLoop {
617-
group.enter()
620+
618621
queue.async {
619622

620623
for j in 0..<innerLoop {
621624
span.setData(value: value, key: "\(i)-\(j)")
622625
span.setTag(value: value, key: "\(i)-\(j)")
623626
}
624627

625-
group.leave()
628+
expectation.fulfill()
626629
}
627630
}
628631

629632
queue.activate()
630-
group.wait()
633+
wait(for: [expectation], timeout: 10.0)
634+
631635
let threadDataItemCount = 2
632636
XCTAssertEqual(span.data.count, outerLoop * innerLoop + threadDataItemCount)
633637
}

0 commit comments

Comments
 (0)