@@ -98,48 +98,58 @@ final class SentryHttpTransportFlushIntegrationTests: XCTestCase {
98
98
for _ in 0 ..< 30 {
99
99
sut. send ( envelope: SentryEnvelope ( event: Event ( ) ) )
100
100
}
101
- // Wait until the dispath queue drains to confirm the envelope is stored
101
+ // Wait until the dispatch queue drains to confirm the envelope is stored
102
102
waitForEnvelopeToBeStored ( dispatchQueueWrapper)
103
103
requestManager. returnResponse ( response: HTTPURLResponse ( ) )
104
104
105
- let initialFlushCallGroup = DispatchGroup ( )
106
- let ensureFlushingGroup = DispatchGroup ( )
105
+ let initialFlushCallExpectation = XCTestExpectation ( description: " Initial flush call should succeed " )
106
+ initialFlushCallExpectation. assertForOverFulfill = true
107
+
108
+ let ensureFlushingExpectation = XCTestExpectation ( description: " Ensure flushing is called " )
109
+ ensureFlushingExpectation. assertForOverFulfill = true
110
+
107
111
let ensureFlushingQueue = DispatchQueue ( label: " First flushing " )
108
112
109
113
sut. setStartFlushCallback {
110
- ensureFlushingGroup . leave ( )
114
+ ensureFlushingExpectation . fulfill ( )
111
115
}
112
116
113
- initialFlushCallGroup. enter ( )
114
- ensureFlushingGroup. enter ( )
115
117
ensureFlushingQueue. async {
116
118
XCTAssertEqual ( . success, sut. flush ( flushTimeout) , " Initial call to flush should succeed " )
117
- initialFlushCallGroup . leave ( )
119
+ initialFlushCallExpectation . fulfill ( )
118
120
}
119
121
120
122
// Ensure transport is flushing.
121
- ensureFlushingGroup . waitWithTimeout ( )
123
+ wait ( for : [ ensureFlushingExpectation ] , timeout : 10.0 )
122
124
123
125
// Now the transport should also have left the synchronized block, and the
124
126
// flush should return immediately.
125
127
126
- let parallelFlushCallsGroup = DispatchGroup ( )
128
+ let loopCount = 2
129
+ let parallelFlushCallsExpectation = XCTestExpectation ( description: " Parallel flush calls should return immediately " )
130
+ parallelFlushCallsExpectation. expectedFulfillmentCount = loopCount
131
+ parallelFlushCallsExpectation. assertForOverFulfill = true
132
+
127
133
let initiallyInactiveQueue = DispatchQueue ( label: " testFlush_CalledMultipleTimes_ImmediatelyReturnsFalse " , qos: . userInitiated, attributes: [ . concurrent, . initiallyInactive] )
128
- for _ in 0 ..< 2 {
129
- parallelFlushCallsGroup . enter ( )
134
+ for _ in 0 ..< loopCount {
135
+
130
136
initiallyInactiveQueue. async {
131
137
for _ in 0 ..< 10 {
132
138
XCTAssertEqual ( . alreadyFlushing, sut. flush ( flushTimeout) , " Flush should have returned immediately " )
133
139
}
134
140
135
- parallelFlushCallsGroup . leave ( )
141
+ parallelFlushCallsExpectation . fulfill ( )
136
142
}
137
143
}
138
144
139
145
initiallyInactiveQueue. activate ( )
140
- parallelFlushCallsGroup. waitWithTimeout ( )
146
+ wait ( for: [ parallelFlushCallsExpectation] , timeout: 10.0 )
147
+
141
148
requestManager. responseDispatchGroup. leave ( )
142
- initialFlushCallGroup. waitWithTimeout ( )
149
+
150
+ // The initial call to flush is blocking and will take some time to finish.
151
+ // Therefore, we wait at the end of the test.
152
+ wait ( for: [ initialFlushCallExpectation] , timeout: 10.0 )
143
153
}
144
154
145
155
// We use the test name as part of the DSN to ensure that each test runs in isolation.
0 commit comments