@@ -1146,13 +1146,16 @@ class SentryTracerTests: XCTestCase {
1146
1146
let child = sut. startChild ( operation: fixture. transactionOperation)
1147
1147
sut. finish ( )
1148
1148
1149
- let queue = DispatchQueue ( label: " SentryTracerTests " , attributes: [ . concurrent, . initiallyInactive] )
1150
- let group = DispatchGroup ( )
1151
-
1152
1149
let children = 5
1153
1150
let grandchildren = 10
1151
+
1152
+ let queue = DispatchQueue ( label: " SentryTracerTests " , attributes: [ . concurrent, . initiallyInactive] )
1153
+ let expectation = XCTestExpectation ( description: " Finish Children Async " )
1154
+ expectation. expectedFulfillmentCount = children
1155
+ expectation. assertForOverFulfill = true
1156
+
1154
1157
for _ in 0 ..< children {
1155
- group . enter ( )
1158
+
1156
1159
queue. async {
1157
1160
let grandChild = child. startChild ( operation: self . fixture. transactionOperation)
1158
1161
for _ in 0 ..< grandchildren {
@@ -1162,12 +1165,14 @@ class SentryTracerTests: XCTestCase {
1162
1165
1163
1166
grandChild. finish ( )
1164
1167
self . assertTransactionNotCaptured ( sut)
1165
- group. leave ( )
1168
+
1169
+ expectation. fulfill ( )
1166
1170
}
1167
1171
}
1168
1172
1169
1173
queue. activate ( )
1170
- group. wait ( )
1174
+
1175
+ wait ( for: [ expectation] , timeout: 10.0 )
1171
1176
1172
1177
child. finish ( )
1173
1178
@@ -1225,32 +1230,40 @@ class SentryTracerTests: XCTestCase {
1225
1230
}
1226
1231
1227
1232
let queue = DispatchQueue ( label: " SentryTracerTests " , attributes: [ . concurrent, . initiallyInactive] )
1228
- let group = DispatchGroup ( )
1229
1233
1230
- func addChildrenAsync( ) {
1231
- for _ in 0 ..< 100 {
1232
- group. enter ( )
1233
- queue. async {
1234
- let child = sut. startChild ( operation: self . fixture. transactionOperation)
1235
- Dynamic ( child) . frames = [ ] as [ Frame ]
1236
- child. finish ( )
1237
- group. leave ( )
1238
- }
1234
+ let addChildrenCount = 100
1235
+ let expectation = XCTestExpectation ( description: " Add spans while finishing " )
1236
+ expectation. expectedFulfillmentCount = addChildrenCount * 2 + 1
1237
+ expectation. assertForOverFulfill = true
1238
+
1239
+ for _ in 0 ..< 100 {
1240
+ queue. async {
1241
+ let child = sut. startChild ( operation: self . fixture. transactionOperation)
1242
+ Dynamic ( child) . frames = [ ] as [ Frame ]
1243
+ child. finish ( )
1244
+
1245
+ expectation. fulfill ( )
1239
1246
}
1240
1247
}
1241
1248
1242
- addChildrenAsync ( )
1243
-
1244
- group. enter ( )
1245
1249
queue. async {
1246
1250
sut. finish ( )
1247
- group . leave ( )
1251
+ expectation . fulfill ( )
1248
1252
}
1249
1253
1250
- addChildrenAsync ( )
1254
+ for _ in 0 ..< 100 {
1255
+ queue. async {
1256
+ let child = sut. startChild ( operation: self . fixture. transactionOperation)
1257
+ Dynamic ( child) . frames = [ ] as [ Frame ]
1258
+ child. finish ( )
1259
+
1260
+ expectation. fulfill ( )
1261
+ }
1262
+ }
1251
1263
1252
1264
queue. activate ( )
1253
- group. wait ( )
1265
+
1266
+ wait ( for: [ expectation] , timeout: 10.0 )
1254
1267
1255
1268
let spans = try XCTUnwrap ( try getSerializedTransaction ( ) [ " spans " ] ! as? [ [ String : Any ] ] )
1256
1269
XCTAssertGreaterThanOrEqual ( spans. count, children)
0 commit comments