Skip to content

Commit bb7da60

Browse files
test: Disable logs for verbose tracer tests (#4241)
Disable logs for testAddingSpansOnDifferentThread_WhileFinishing_DoesNotCrash because it can logs around 5K log messages.
1 parent c42dfa3 commit bb7da60

File tree

1 file changed

+98
-92
lines changed

1 file changed

+98
-92
lines changed

Tests/SentryTests/Transaction/SentryTracerTests.swift

Lines changed: 98 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -207,38 +207,39 @@ class SentryTracerTests: XCTestCase {
207207
/// to a crash when spans keep finishing while finishInternal is executed because
208208
/// shouldIgnoreWaitForChildrenCallback could be then nil in hasUnfinishedChildSpansToWaitFor.
209209
func testFinish_ShouldIgnoreWaitForChildrenCallback_DoesNotCrash() throws {
210-
211-
for _ in 0..<5 {
212-
let sut = fixture.getSut()
213-
214-
let dispatchQueue = DispatchQueue(label: "test", attributes: [.concurrent, .initiallyInactive])
215-
216-
let expectation = expectation(description: "call everything")
217-
expectation.expectedFulfillmentCount = 11
218-
219-
sut.shouldIgnoreWaitForChildrenCallback = { _ in
220-
return true
221-
}
222-
223-
for _ in 0..<1_000 {
224-
let child = sut.startChild(operation: self.fixture.transactionOperation)
225-
child.finish()
226-
}
227-
228-
dispatchQueue.async {
229-
for _ in 0..<10 {
210+
SentryLog.withOutLogs {
211+
for _ in 0..<5 {
212+
let sut = fixture.getSut()
213+
214+
let dispatchQueue = DispatchQueue(label: "test", attributes: [.concurrent, .initiallyInactive])
215+
216+
let expectation = expectation(description: "call everything")
217+
expectation.expectedFulfillmentCount = 11
218+
219+
sut.shouldIgnoreWaitForChildrenCallback = { _ in
220+
return true
221+
}
222+
223+
for _ in 0..<1_000 {
230224
let child = sut.startChild(operation: self.fixture.transactionOperation)
231225
child.finish()
226+
}
227+
228+
dispatchQueue.async {
229+
for _ in 0..<10 {
230+
let child = sut.startChild(operation: self.fixture.transactionOperation)
231+
child.finish()
232+
expectation.fulfill()
233+
}
234+
}
235+
dispatchQueue.async {
236+
sut.finish()
232237
expectation.fulfill()
233238
}
239+
240+
dispatchQueue.activate()
241+
wait(for: [expectation], timeout: 1.0)
234242
}
235-
dispatchQueue.async {
236-
sut.finish()
237-
expectation.fulfill()
238-
}
239-
240-
dispatchQueue.activate()
241-
wait(for: [expectation], timeout: 1.0)
242243
}
243244
}
244245

@@ -1083,39 +1084,41 @@ class SentryTracerTests: XCTestCase {
10831084
}
10841085

10851086
func testFinishAsync() throws {
1086-
let sut = fixture.getSut()
1087-
let child = sut.startChild(operation: fixture.transactionOperation)
1088-
sut.finish()
1089-
1090-
let queue = DispatchQueue(label: "SentryTracerTests", attributes: [.concurrent, .initiallyInactive])
1091-
let group = DispatchGroup()
1092-
1093-
let children = 5
1094-
let grandchildren = 10
1095-
for _ in 0 ..< children {
1096-
group.enter()
1097-
queue.async {
1098-
let grandChild = child.startChild(operation: self.fixture.transactionOperation)
1099-
for _ in 0 ..< grandchildren {
1100-
let grandGrandChild = grandChild.startChild(operation: self.fixture.transactionOperation)
1101-
grandGrandChild.finish()
1087+
try SentryLog.withOutLogs {
1088+
let sut = fixture.getSut()
1089+
let child = sut.startChild(operation: fixture.transactionOperation)
1090+
sut.finish()
1091+
1092+
let queue = DispatchQueue(label: "SentryTracerTests", attributes: [.concurrent, .initiallyInactive])
1093+
let group = DispatchGroup()
1094+
1095+
let children = 5
1096+
let grandchildren = 10
1097+
for _ in 0 ..< children {
1098+
group.enter()
1099+
queue.async {
1100+
let grandChild = child.startChild(operation: self.fixture.transactionOperation)
1101+
for _ in 0 ..< grandchildren {
1102+
let grandGrandChild = grandChild.startChild(operation: self.fixture.transactionOperation)
1103+
grandGrandChild.finish()
1104+
}
1105+
1106+
grandChild.finish()
1107+
self.assertTransactionNotCaptured(sut)
1108+
group.leave()
11021109
}
1103-
1104-
grandChild.finish()
1105-
self.assertTransactionNotCaptured(sut)
1106-
group.leave()
11071110
}
1111+
1112+
queue.activate()
1113+
group.wait()
1114+
1115+
child.finish()
1116+
1117+
assertOneTransactionCaptured(sut)
1118+
1119+
let spans = try XCTUnwrap(try getSerializedTransaction()["spans"]! as? [[String: Any]])
1120+
XCTAssertEqual(spans.count, children * (grandchildren + 1) + 1)
11081121
}
1109-
1110-
queue.activate()
1111-
group.wait()
1112-
1113-
child.finish()
1114-
1115-
assertOneTransactionCaptured(sut)
1116-
1117-
let spans = try XCTUnwrap(try getSerializedTransaction()["spans"]! as? [[String: Any]])
1118-
XCTAssertEqual(spans.count, children * (grandchildren + 1) + 1)
11191122
}
11201123

11211124
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
@@ -1152,44 +1155,47 @@ class SentryTracerTests: XCTestCase {
11521155
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
11531156

11541157
func testAddingSpansOnDifferentThread_WhileFinishing_DoesNotCrash() throws {
1155-
let sut = fixture.getSut(waitForChildren: false)
1156-
1157-
let children = 1_000
1158-
for _ in 0..<children {
1159-
let child = sut.startChild(operation: self.fixture.transactionOperation)
1160-
child.finish()
1161-
}
1162-
1163-
let queue = DispatchQueue(label: "SentryTracerTests", attributes: [.concurrent, .initiallyInactive])
1164-
let group = DispatchGroup()
1165-
1166-
func addChildrenAsync() {
1167-
for _ in 0 ..< 100 {
1168-
group.enter()
1169-
queue.async {
1170-
let child = sut.startChild(operation: self.fixture.transactionOperation)
1171-
Dynamic(child).frames = [] as [Frame]
1172-
child.finish()
1173-
group.leave()
1158+
try SentryLog.withOutLogs {
1159+
1160+
let sut = fixture.getSut(waitForChildren: false)
1161+
1162+
let children = 1_000
1163+
for _ in 0..<children {
1164+
let child = sut.startChild(operation: self.fixture.transactionOperation)
1165+
child.finish()
1166+
}
1167+
1168+
let queue = DispatchQueue(label: "SentryTracerTests", attributes: [.concurrent, .initiallyInactive])
1169+
let group = DispatchGroup()
1170+
1171+
func addChildrenAsync() {
1172+
for _ in 0 ..< 100 {
1173+
group.enter()
1174+
queue.async {
1175+
let child = sut.startChild(operation: self.fixture.transactionOperation)
1176+
Dynamic(child).frames = [] as [Frame]
1177+
child.finish()
1178+
group.leave()
1179+
}
11741180
}
11751181
}
1182+
1183+
addChildrenAsync()
1184+
1185+
group.enter()
1186+
queue.async {
1187+
sut.finish()
1188+
group.leave()
1189+
}
1190+
1191+
addChildrenAsync()
1192+
1193+
queue.activate()
1194+
group.wait()
1195+
1196+
let spans = try XCTUnwrap(try getSerializedTransaction()["spans"]! as? [[String: Any]])
1197+
XCTAssertGreaterThanOrEqual(spans.count, children)
11761198
}
1177-
1178-
addChildrenAsync()
1179-
1180-
group.enter()
1181-
queue.async {
1182-
sut.finish()
1183-
group.leave()
1184-
}
1185-
1186-
addChildrenAsync()
1187-
1188-
queue.activate()
1189-
group.wait()
1190-
1191-
let spans = try XCTUnwrap(try getSerializedTransaction()["spans"]! as? [[String: Any]])
1192-
XCTAssertGreaterThanOrEqual(spans.count, children)
11931199
}
11941200

11951201
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)

0 commit comments

Comments
 (0)