Skip to content

Commit acac774

Browse files
test: Data race in testReportFullyDisplayed (#5499)
Setting a new TestTimeToDisplayTracker to the SentryDependencyContainer directly after starting the SDK led to a data race in sentry_sdkInitProfilerTasks, because sentry_sdkInitProfilerTasks accesses the TimeToDisplayTracker on a BG thread. This is fixed now by setting the TestTimeToDisplayTracker to the SentryDependencyContainer before starting the SDK.
1 parent 9be5373 commit acac774

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Tests/SentryTests/SentrySDKTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,14 @@ class SentrySDKTests: XCTestCase {
728728
func testReportFullyDisplayed() {
729729
fixture.options.enableTimeToFullDisplayTracing = true
730730

731-
SentrySDK.start(options: fixture.options)
732-
733731
let testTTDTracker = TestTimeToDisplayTracker(waitForFullDisplay: true)
734-
735732
let performanceTracker = Dynamic(SentryDependencyContainer.sharedInstance().uiViewControllerPerformanceTracker)
736733
performanceTracker.currentTTDTracker = testTTDTracker
737734

735+
// Start SDK after setting up the tracker to ensure we're changing the tracker during it's initialization,
736+
// because some initialization logic happens on a BG thread and we would end up in a race condition.
737+
SentrySDK.start(options: fixture.options)
738+
738739
SentrySDK.reportFullyDisplayed()
739740

740741
XCTAssertTrue(testTTDTracker.registerFullDisplayCalled)

0 commit comments

Comments
 (0)