Skip to content

Commit 2c59847

Browse files
test: Improve FileManager PathTooLong assert (#6510)
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.
1 parent 6b01cf3 commit 2c59847

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Tests/SentryTests/Helper/SentryFileManagerTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,13 +1082,19 @@ class SentryFileManagerTests: XCTestCase {
10821082

10831083
let path = fixture.getTooLongPath()
10841084
var error: NSError?
1085+
10851086
// -- Act --
10861087
let result = createDirectoryIfNotExists(path, &error)
1088+
10871089
// -- Assert -
10881090
XCTAssertFalse(result)
10891091
XCTAssertEqual(error?.domain, SentryErrorDomain)
10901092
XCTAssertEqual(error?.code, 108)
1091-
XCTAssertEqual(logOutput.loggedMessages.count, 1)
1093+
1094+
let expectedLogMessage = "Failed to create directory, path is too long: \(path)"
1095+
let logMessagesContainsExpected = logOutput.loggedMessages.contains { $0.contains("[Sentry] [fatal]") && $0.contains(expectedLogMessage) }
1096+
1097+
XCTAssertTrue(logMessagesContainsExpected, "Expected fatal log with message: \(expectedLogMessage)")
10921098
}
10931099

10941100
func testCreateDirectoryIfNotExists_otherError_shouldNotLogError() throws {

Tests/SentryTests/Integrations/WatchdogTerminations/SentryWatchdogTerminationTrackerTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class SentryWatchdogTerminationTrackerTests: NotificationCenterTestCase {
108108
let appState = SentryAppState(releaseName: fixture.options.releaseName ?? "", osVersion: UIDevice.current.systemVersion, vendorId: TestData.someUUID, isDebugging: false, systemBootTimestamp: fixture.sysctl.systemBootTimestamp)
109109

110110
XCTAssertEqual(appState, actual)
111-
XCTAssertEqual(1, fixture.dispatchQueue.dispatchAsyncCalled)
111+
112+
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.")
112113
}
113114

114115
func testGoToForeground_SetsIsActive() throws {
@@ -126,7 +127,7 @@ class SentryWatchdogTerminationTrackerTests: NotificationCenterTestCase {
126127
let appState2 = try XCTUnwrap(fixture.fileManager.readAppState())
127128
XCTAssertFalse(appState2.isActive, "Expected appSate to be inactive after going to background.")
128129

129-
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. ")
130+
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.")
130131
}
131132

132133
func testGoToForeground_WhenAppStateNil_NothingIsStored() {

0 commit comments

Comments
 (0)