Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Extra test for PR #4526 #4531

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -814,6 +815,97 @@ 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
}

// 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()
brustolin marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
Loading