From 7eeee4a9e4e7d4ab253eb26233bed85c55853c6a Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 13 Nov 2024 11:22:14 +0100 Subject: [PATCH 1/3] Update SentryUIViewControllerPerformanceTrackerTests.swift --- ...iewControllerPerformanceTrackerTests.swift | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift index fc96fee371..4c796b0c12 100644 --- a/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift @@ -48,6 +48,7 @@ class SentryUIViewControllerPerformanceTrackerTests: XCTestCase { encoding: .utf8)! as NSString options.add(inAppInclude: imageName.lastPathComponent) options.debug = true + options.enableTimeToFullDisplayTracing = true framesTracker = SentryFramesTracker(displayLinkWrapper: displayLinkWrapper, dateProvider: dateProvider, dispatchQueueWrapper: TestSentryDispatchQueueWrapper(), notificationCenter: TestNSNotificationCenterWrapper(), keepDelayedFramesDuration: 0) @@ -814,6 +815,95 @@ class SentryUIViewControllerPerformanceTrackerTests: XCTestCase { XCTAssertFalse(secondFullDisplaySpan.isFinished) } + func test_waitForFullDisplay_NewViewControllerLoaded_BeforeReportTTFD_withBackgroundWork() throws { + class CustomVC : UIViewController { + var workSpan: Span? + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + //Start some work, it could be a http request + workSpan = SentrySDK.span?.startChild(operation: "Work") + } + + // We will use a function to finish the work + // but it could be the request response + func finishWork() { + workSpan?.finish() + SentrySDK.reportFullyDisplayed() + } + } + + let dateProvider = fixture.dateProvider + let sut = fixture.getSut() + let tracker = fixture.tracker + let firstController = CustomVC() + let secondController = CustomVC() + + var firstTracer: SentryTracer? + var secondTracer: SentryTracer? + + sut.enableWaitForFullDisplay = true + + dateProvider.advance(by: 1) + sut.viewControllerLoadView(firstController) { + firstController.loadView() + firstTracer = self.getStack(tracker).first as? SentryTracer + } + + sut.viewControllerViewDidLoad(firstController) { + firstController.viewDidLoad() + } + + dateProvider.advance(by: 1) + sut.viewControllerViewWillAppear(firstController) { + firstController.viewWillAppear(false) + } + + sut.viewControllerViewDidAppear(firstController) { + firstController.viewDidAppear(false) + } + + fixture.displayLinkWrapper.normalFrame() + + let firstFullDisplaySpan = try XCTUnwrap(firstTracer?.children.first { $0.operation == "ui.load.full_display" }) + + XCTAssertFalse(firstFullDisplaySpan.isFinished) + + XCTAssertEqual(firstTracer?.traceId, SentrySDK.span?.traceId) + + dateProvider.advance(by: 1) + sut.viewControllerLoadView(secondController) { + secondController.loadView() + secondTracer = self.getStack(tracker).first as? SentryTracer + } + + dateProvider.advance(by: 1) + firstController.finishWork() + fixture.displayLinkWrapper.normalFrame() + + dateProvider.advance(by: 1) + sut.viewControllerViewWillAppear(secondController) { + secondController.viewWillAppear(false) + } + sut.viewControllerViewDidAppear(secondController) { + secondController.viewDidAppear(false) + } + fixture.displayLinkWrapper.normalFrame() + + dateProvider.advance(by: 1) + let timeOfSecondControllerFinishWork = dateProvider.date() + secondController.finishWork() + + fixture.displayLinkWrapper.normalFrame() + + XCTAssertTrue(firstFullDisplaySpan.isFinished) + XCTAssertEqual(.deadlineExceeded, firstFullDisplaySpan.status) + + let secondFullDisplaySpan = try XCTUnwrap(secondTracer?.children.first { $0.operation == "ui.load.full_display" }) + + XCTAssertEqual(secondFullDisplaySpan.timestamp, timeOfSecondControllerFinishWork) + } + func test_waitForFullDisplay_NewViewControllerLoaded_BeforeReportTTFD_FramesTrackerStopped() throws { let sut = fixture.getSut() let tracker = fixture.tracker From c1993118ec3dc6867e3ad76423dce50ca51343ce Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 13 Nov 2024 10:24:22 +0000 Subject: [PATCH 2/3] Format code --- .../SentryUIViewControllerPerformanceTrackerTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift index 4c796b0c12..20e30f447d 100644 --- a/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift @@ -816,7 +816,7 @@ class SentryUIViewControllerPerformanceTrackerTests: XCTestCase { } func test_waitForFullDisplay_NewViewControllerLoaded_BeforeReportTTFD_withBackgroundWork() throws { - class CustomVC : UIViewController { + class CustomVC: UIViewController { var workSpan: Span? override func viewDidAppear(_ animated: Bool) { From 4ff33ee2db78dd1b05c69447514585778a9c65ff Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 13 Nov 2024 11:26:22 +0100 Subject: [PATCH 3/3] Update Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift --- .../SentryUIViewControllerPerformanceTrackerTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift index 20e30f447d..967555d09a 100644 --- a/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/UIViewController/SentryUIViewControllerPerformanceTrackerTests.swift @@ -877,6 +877,8 @@ class SentryUIViewControllerPerformanceTrackerTests: XCTestCase { secondTracer = self.getStack(tracker).first as? SentryTracer } + // The work of the first controller asynchronously ended here, and a new frame was rendered + // while the second controller hasn’t appeared yet. dateProvider.advance(by: 1) firstController.finishWork() fixture.displayLinkWrapper.normalFrame()