-
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The end of the segment was equal the time the last frame was taken, by the end should be the last frame date plus the duration of the frame
- Loading branch information
Showing
8 changed files
with
197 additions
and
45 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
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
125 changes: 125 additions & 0 deletions
125
Tests/SentryTests/Integrations/SessionReplay/SentryOnDemandReplayTests.swift
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import Foundation | ||
import Nimble | ||
@testable import Sentry | ||
import SentryTestUtils | ||
import XCTest | ||
|
||
#if os(iOS) || os(tvOS) | ||
class SentryOnDemandReplayTests: XCTestCase { | ||
|
||
let dateProvider = TestCurrentDateProvider() | ||
let outputPath = FileManager.default.temporaryDirectory | ||
|
||
func getSut() -> SentryOnDemandReplay { | ||
let sut = SentryOnDemandReplay(outputPath: outputPath.path, | ||
workingQueue: TestSentryDispatchQueueWrapper(), | ||
dateProvider: dateProvider) | ||
return sut | ||
} | ||
|
||
func testAddFrame() { | ||
let sut = getSut() | ||
sut.addFrameAsync(image: UIImage.add) | ||
|
||
guard let frame = sut.frames.first else { | ||
fail("Frame was not saved") | ||
return | ||
} | ||
|
||
expect(FileManager.default.fileExists(atPath: frame.imagePath)) == true | ||
expect(frame.imagePath.hasPrefix(self.outputPath.path)) == true | ||
} | ||
|
||
func testReleaseFrames() { | ||
let sut = getSut() | ||
|
||
for _ in 0..<10 { | ||
sut.addFrameAsync(image: UIImage.add) | ||
dateProvider.advance(by: 1) | ||
} | ||
|
||
sut.releaseFramesUntil(dateProvider.date().addingTimeInterval(-5)) | ||
|
||
let frames = sut.frames | ||
|
||
expect(frames.count) == 5 | ||
expect(frames.first?.time) == Date(timeIntervalSinceReferenceDate: 5) | ||
expect(frames.last?.time) == Date(timeIntervalSinceReferenceDate: 9) | ||
} | ||
|
||
func testGenerateVideo() { | ||
let sut = getSut() | ||
dateProvider.driftTimeForEveryRead = true | ||
dateProvider.driftTimeInterval = 1 | ||
|
||
for _ in 0..<10 { | ||
sut.addFrameAsync(image: UIImage.add) | ||
} | ||
|
||
let output = FileManager.default.temporaryDirectory.appendingPathComponent("video.mp4") | ||
let videoExpectation = expectation(description: "Wait for video render") | ||
|
||
try? sut.createVideoWith(duration: 10, beginning: Date(timeIntervalSinceReferenceDate: 0), outputFileURL: output) { info, error in | ||
expect(error) == nil | ||
|
||
expect(info?.duration) == 10 | ||
expect(info?.start) == Date(timeIntervalSinceReferenceDate: 0) | ||
expect(info?.end) == Date(timeIntervalSinceReferenceDate: 10) | ||
|
||
expect(FileManager.default.fileExists(atPath: output.path)) == true | ||
videoExpectation.fulfill() | ||
try? FileManager.default.removeItem(at: output) | ||
} | ||
|
||
wait(for: [videoExpectation], timeout: 1) | ||
} | ||
|
||
func testAddFrameIsThreadSafe() { | ||
let queue = SentryDispatchQueueWrapper() | ||
let sut = SentryOnDemandReplay(outputPath: outputPath.path, | ||
workingQueue: queue, | ||
dateProvider: dateProvider) | ||
|
||
dateProvider.driftTimeForEveryRead = true | ||
dateProvider.driftTimeInterval = 1 | ||
let group = DispatchGroup() | ||
|
||
for _ in 0..<10 { | ||
group.enter() | ||
DispatchQueue.global().async { | ||
sut.addFrameAsync(image: UIImage.add) | ||
group.leave() | ||
} | ||
} | ||
|
||
group.wait() | ||
queue.queue.sync {} //Wait for all enqueued operation to finish | ||
expect(sut.frames.map({ ($0.imagePath as NSString).lastPathComponent })) == (0..<10).map { "\($0).png" } | ||
} | ||
|
||
func testReleaseIsThreadSafe() { | ||
let queue = SentryDispatchQueueWrapper() | ||
let sut = SentryOnDemandReplay(outputPath: outputPath.path, | ||
workingQueue: queue, | ||
dateProvider: dateProvider) | ||
|
||
sut.frames = (0..<100).map { SentryReplayFrame(imagePath: outputPath.path + "/\($0).png", time: Date(timeIntervalSinceReferenceDate: Double($0))) } | ||
|
||
let group = DispatchGroup() | ||
|
||
for i in 1...10 { | ||
group.enter() | ||
DispatchQueue.global().async { | ||
sut.releaseFramesUntil(Date(timeIntervalSinceReferenceDate: Double(i) * 10.0)) | ||
group.leave() | ||
} | ||
} | ||
|
||
group.wait() | ||
|
||
queue.queue.sync {} //Wait for all enqueued operation to finish | ||
expect(sut.frames.count) == 0 | ||
} | ||
|
||
} | ||
#endif |
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