@@ -61,7 +61,9 @@ class SamplerTests: ParselyTestCase {
6161 Timer . scheduledTimer ( withTimeInterval: heartbeatDeliveryInterval, repeats: false ) { timer in
6262 expectation. fulfill ( )
6363 }
64- waitForExpectations ( timeout: heartbeatDeliveryInterval, handler: nil )
64+ // Wait slightly longer to reduce the race between waiting for the `expectation` to be
65+ // fulfilled and the fulfillment.
66+ waitForExpectations ( timeout: heartbeatDeliveryInterval + 0.01 , handler: nil )
6567
6668 let actualUpdatedInterval = samplerUnderTest!. heartbeatInterval
6769 // This value depends on heartbeatInterval, and two magic numbers in the implementation.
@@ -160,8 +162,12 @@ class SamplerTests: ParselyTestCase {
160162
161163 let accumulatedTime : TimeInterval = samplerUnderTest!. accumulators [ " sampler-test " ] !. accumulatedTime
162164 samplerUnderTest!. pause ( )
163- XCTAssert ( accumulatedTime >= assertionTimeout - acceptableDifference,
164- " The sampler should accumulate time constantly after a call to trackKey " )
165+ XCTAssertEqual (
166+ accumulatedTime,
167+ assertionTimeout,
168+ accuracy: acceptableDifference,
169+ " The sampler should accumulate time constantly after a call to trackKey "
170+ )
165171
166172 let secondExpectation = self . expectation ( description: " Paused sampling " )
167173 Timer . scheduledTimer ( withTimeInterval: assertionTimeout, repeats: false ) { timer in
@@ -170,6 +176,11 @@ class SamplerTests: ParselyTestCase {
170176 waitForExpectations ( timeout: assertionTimeout + acceptableDifference, handler: nil )
171177
172178 let secondAccumulatedTime : TimeInterval = samplerUnderTest!. accumulators [ " sampler-test " ] !. accumulatedTime
173- XCTAssert ( secondAccumulatedTime <= assertionTimeout, " AccumulatedTime was \( secondAccumulatedTime) " )
179+ XCTAssertEqual (
180+ secondAccumulatedTime,
181+ assertionTimeout,
182+ accuracy: acceptableDifference,
183+ " AccumulatedTime was \( secondAccumulatedTime) "
184+ )
174185 }
175186}
0 commit comments