diff --git a/SentryTestUtils/TestDisplayLinkWrapper.swift b/SentryTestUtils/TestDisplayLinkWrapper.swift index 9db29f7dbcd..4110f52e1a5 100644 --- a/SentryTestUtils/TestDisplayLinkWrapper.swift +++ b/SentryTestUtils/TestDisplayLinkWrapper.swift @@ -23,11 +23,19 @@ public class TestDisplayLinkWrapper: SentryDisplayLinkWrapper { public var target: AnyObject! public var selector: Selector! public var currentFrameRate: FrameRate = .low - let frozenFrameThreshold = 0.7 + + private let frozenFrameThreshold = 0.7 + private let slowestSlowFrameDuration: Double + private let fastestFrozenFrameDuration: Double + public var dateProvider: TestCurrentDateProvider public init(dateProvider: TestCurrentDateProvider = TestCurrentDateProvider()) { self.dateProvider = dateProvider + // The test date provider converts the duration from UInt64 to a double back and forth. + // Therefore we have rounding issues, and subtract or add the timeEpsilon. + slowestSlowFrameDuration = frozenFrameThreshold - timeEpsilon + fastestFrozenFrameDuration = frozenFrameThreshold + timeEpsilon } public var linkInvocations = Invocations() @@ -80,16 +88,15 @@ public class TestDisplayLinkWrapper: SentryDisplayLinkWrapper { } public func slowestSlowFrame() -> CFTimeInterval { - dateProvider.advance(by: frozenFrameThreshold) + dateProvider.advance(by: slowestSlowFrameDuration) call() - return frozenFrameThreshold + return slowestSlowFrameDuration } public func fastestFrozenFrame() -> CFTimeInterval { - let duration: Double = frozenFrameThreshold + timeEpsilon - dateProvider.advance(by: duration) + dateProvider.advance(by: fastestFrozenFrameDuration) call() - return duration + return fastestFrozenFrameDuration } /// There's no upper bound for a frozen frame, except maybe for the watchdog time limit. diff --git a/Tests/SentryTests/Integrations/Performance/FramesTracking/SentryFramesTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/FramesTracking/SentryFramesTrackerTests.swift index 16bd53155af..6e8d6824fb6 100644 --- a/Tests/SentryTests/Integrations/Performance/FramesTracking/SentryFramesTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/FramesTracking/SentryFramesTrackerTests.swift @@ -84,6 +84,20 @@ class SentryFramesTrackerTests: XCTestCase { try assert(slow: 2, frozen: 0, total: 3) } + + func testMultipleSlowestSlowFrames() throws { + let sut = fixture.sut + sut.start() + + fixture.displayLinkWrapper.call() + + let slowFramesCount: UInt = 20 + for _ in 0..