@@ -207,38 +207,39 @@ class SentryTracerTests: XCTestCase {
207
207
/// to a crash when spans keep finishing while finishInternal is executed because
208
208
/// shouldIgnoreWaitForChildrenCallback could be then nil in hasUnfinishedChildSpansToWaitFor.
209
209
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 {
230
224
let child = sut. startChild ( operation: self . fixture. transactionOperation)
231
225
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 ( )
232
237
expectation. fulfill ( )
233
238
}
239
+
240
+ dispatchQueue. activate ( )
241
+ wait ( for: [ expectation] , timeout: 1.0 )
234
242
}
235
- dispatchQueue. async {
236
- sut. finish ( )
237
- expectation. fulfill ( )
238
- }
239
-
240
- dispatchQueue. activate ( )
241
- wait ( for: [ expectation] , timeout: 1.0 )
242
243
}
243
244
}
244
245
@@ -1083,39 +1084,41 @@ class SentryTracerTests: XCTestCase {
1083
1084
}
1084
1085
1085
1086
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 ( )
1102
1109
}
1103
-
1104
- grandChild. finish ( )
1105
- self . assertTransactionNotCaptured ( sut)
1106
- group. leave ( )
1107
1110
}
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 )
1108
1121
}
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 )
1119
1122
}
1120
1123
1121
1124
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
@@ -1152,44 +1155,47 @@ class SentryTracerTests: XCTestCase {
1152
1155
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
1153
1156
1154
1157
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
+ }
1174
1180
}
1175
1181
}
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)
1176
1198
}
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)
1193
1199
}
1194
1200
1195
1201
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
0 commit comments