From 57d3baa5569d2fe2af5c73a2e0201016165e134f Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Thu, 23 Oct 2025 10:16:37 +0200 Subject: [PATCH 1/2] test: Improve FileManager PathTooLong assert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the test verified the number of logged messages, causing fragile failures if unrelated logs were added. Now it asserts the presence of the specific fatal log message, ensuring stability even when additional logs are introduced. --- Tests/SentryTests/Helper/SentryFileManagerTests.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/SentryTests/Helper/SentryFileManagerTests.swift b/Tests/SentryTests/Helper/SentryFileManagerTests.swift index e186677c5ba..107358e94d4 100644 --- a/Tests/SentryTests/Helper/SentryFileManagerTests.swift +++ b/Tests/SentryTests/Helper/SentryFileManagerTests.swift @@ -1082,13 +1082,19 @@ class SentryFileManagerTests: XCTestCase { let path = fixture.getTooLongPath() var error: NSError? + // -- Act -- let result = createDirectoryIfNotExists(path, &error) + // -- Assert - XCTAssertFalse(result) XCTAssertEqual(error?.domain, SentryErrorDomain) XCTAssertEqual(error?.code, 108) - XCTAssertEqual(logOutput.loggedMessages.count, 1) + + let expectedLogMessage = "Failed to create directory, path is too long: \(path)" + let logMessagesContainsExpected = logOutput.loggedMessages.contains { $0.contains("[Sentry] [fatal]") && $0.contains(expectedLogMessage) } + + XCTAssertTrue(logMessagesContainsExpected, "Expected fatal log with message: \(expectedLogMessage)") } func testCreateDirectoryIfNotExists_otherError_shouldNotLogError() throws { From 1a770fdc4b6255caae44cb2d2daf1d763c88088d Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Thu, 23 Oct 2025 11:49:07 +0200 Subject: [PATCH 2/2] fix testStart_StoresAppState --- .../SentryWatchdogTerminationTrackerTests.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tests/SentryTests/Integrations/WatchdogTerminations/SentryWatchdogTerminationTrackerTests.swift b/Tests/SentryTests/Integrations/WatchdogTerminations/SentryWatchdogTerminationTrackerTests.swift index c2c9b293f3f..646804a1361 100644 --- a/Tests/SentryTests/Integrations/WatchdogTerminations/SentryWatchdogTerminationTrackerTests.swift +++ b/Tests/SentryTests/Integrations/WatchdogTerminations/SentryWatchdogTerminationTrackerTests.swift @@ -108,7 +108,8 @@ class SentryWatchdogTerminationTrackerTests: NotificationCenterTestCase { let appState = SentryAppState(releaseName: fixture.options.releaseName ?? "", osVersion: UIDevice.current.systemVersion, vendorId: TestData.someUUID, isDebugging: false, systemBootTimestamp: fixture.sysctl.systemBootTimestamp) XCTAssertEqual(appState, actual) - XCTAssertEqual(1, fixture.dispatchQueue.dispatchAsyncCalled) + + XCTAssertGreaterThanOrEqual(fixture.dispatchQueue.dispatchAsyncCalled, 1, "Expected at least 1 dispatchAsync call for start to ensure we don't run reading the app state on the calling thread.") } func testGoToForeground_SetsIsActive() throws { @@ -126,7 +127,7 @@ class SentryWatchdogTerminationTrackerTests: NotificationCenterTestCase { let appState2 = try XCTUnwrap(fixture.fileManager.readAppState()) XCTAssertFalse(appState2.isActive, "Expected appSate to be inactive after going to background.") - XCTAssertGreaterThanOrEqual(fixture.dispatchQueue.dispatchAsyncCalled, 3, "Expected at least 3 dispatchAsync calls (start, foreground, background) to ensure we don't run reading the app state on the calling thread. ") + XCTAssertGreaterThanOrEqual(fixture.dispatchQueue.dispatchAsyncCalled, 3, "Expected at least 3 dispatchAsync calls (start, foreground, background) to ensure we don't run reading the app state on the calling thread.") } func testGoToForeground_WhenAppStateNil_NothingIsStored() {