-
-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Delete old session replay files (#4446)
Clean up for old session replay files
- Loading branch information
Showing
5 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,12 +358,47 @@ class SentrySessionReplayIntegrationTests: XCTestCase { | |
XCTAssertTrue(sessionReplay.isFullSession) | ||
} | ||
|
||
func createLastSessionReplay(writeSessionInfo: Bool = true, errorSampleRate: Double = 1) throws { | ||
func testCleanUp() throws { | ||
// Create 3 old Sessions | ||
try createLastSessionReplay() | ||
try createLastSessionReplay() | ||
try createLastSessionReplay() | ||
SentryDependencyContainer.sharedInstance().dispatchQueueWrapper = TestSentryDispatchQueueWrapper() | ||
|
||
// Start the integration with a configuration that will enable it | ||
startSDK(sessionSampleRate: 0, errorSampleRate: 1) | ||
|
||
// Check whether there is only one old session directory and the current session directory | ||
let content = try FileManager.default.contentsOfDirectory(atPath: replayFolder()).filter { name in | ||
!name.hasPrefix("replay") && !name.hasPrefix(".") //remove replay info files and system directories | ||
} | ||
|
||
XCTAssertEqual(content.count, 2) | ||
} | ||
|
||
func testCleanUpWithNoFiles() throws { | ||
let options = Options() | ||
options.dsn = "https://[email protected]/test" | ||
options.cacheDirectoryPath = FileManager.default.temporaryDirectory.path | ||
|
||
let replayFolder = options.cacheDirectoryPath + "/io.sentry/\(options.parsedDsn?.getHash() ?? "")/replay" | ||
let dispatchQueue = TestSentryDispatchQueueWrapper() | ||
SentryDependencyContainer.sharedInstance().dispatchQueueWrapper = dispatchQueue | ||
SentryDependencyContainer.sharedInstance().fileManager = try SentryFileManager(options: options) | ||
|
||
if FileManager.default.fileExists(atPath: replayFolder()) { | ||
try FileManager.default.removeItem(atPath: replayFolder()) | ||
} | ||
|
||
// We can't use SentrySDK.start because the dependency container dispatch queue is used for other tasks. | ||
// Manually starting the integration and initializing it makes the test more controlled. | ||
let integration = SentrySessionReplayIntegration() | ||
integration.install(with: options) | ||
|
||
XCTAssertEqual(dispatchQueue.dispatchAsyncCalled, 0) | ||
} | ||
|
||
func createLastSessionReplay(writeSessionInfo: Bool = true, errorSampleRate: Double = 1) throws { | ||
let replayFolder = replayFolder() | ||
let jsonPath = replayFolder + "/replay.current" | ||
var sessionFolder = UUID().uuidString | ||
let info: [String: Any] = ["replayId": SentryId().sentryIdString, | ||
|
@@ -389,6 +424,13 @@ class SentrySessionReplayIntegrationTests: XCTestCase { | |
sentrySessionReplaySync_writeInfo() | ||
} | ||
} | ||
|
||
func replayFolder() -> String { | ||
let options = Options() | ||
options.dsn = "https://[email protected]/test" | ||
options.cacheDirectoryPath = FileManager.default.temporaryDirectory.path | ||
return options.cacheDirectoryPath + "/io.sentry/\(options.parsedDsn?.getHash() ?? "")/replay" | ||
} | ||
} | ||
|
||
#endif |