Skip to content

Commit 86a01e5

Browse files
committed
fix: remove uptime dependence from recorder test
1 parent 02c70b3 commit 86a01e5

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+RecordingTests.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension RunnerTests {
2020
let recorder = ScreenRecorder(outputPath: "", fps: 30)
2121

2222
XCTAssertEqual(recorder.allocateTimestampForTesting(100), 100)
23-
// Non-vacuity: the allocator must advance an accepted frame past the prior timestamp.
23+
// The helper records each returned value as an accepted frame.
2424
XCTAssertEqual(recorder.allocateTimestampForTesting(0), 101)
2525
}
2626
#endif

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ extension RunnerTests {
199199
}
200200
guard input.isReadyForMoreMediaData else { return }
201201
guard let pixelBuffer = makePixelBuffer(from: cgImage) else { return }
202-
let timestampValue = timestampValue(for: ProcessInfo.processInfo.systemUptime)
202+
let candidateTimestampValue = timestampCandidateValue(for: ProcessInfo.processInfo.systemUptime)
203+
let timestampValue = monotonicTimestampValue(for: candidateTimestampValue)
203204
let timescale = effectiveFps
204205
let timestamp = CMTime(value: timestampValue, timescale: timescale)
205206
if !adaptor.append(pixelBuffer, withPresentationTime: timestamp) {
@@ -213,16 +214,18 @@ extension RunnerTests {
213214
lastTimestampValue = timestampValue
214215
}
215216

216-
private func timestampValue(for nowUptime: TimeInterval) -> Int64 {
217-
if recordingStartUptime == nil {
218-
recordingStartUptime = nowUptime
219-
}
220-
let elapsed = max(0, nowUptime - (recordingStartUptime ?? nowUptime))
221-
let timestampValue = Int64((elapsed * Double(effectiveFps)).rounded(.down))
222-
if timestampValue <= lastTimestampValue {
217+
private func timestampCandidateValue(for nowUptime: TimeInterval) -> Int64 {
218+
let startUptime = recordingStartUptime ?? nowUptime
219+
recordingStartUptime = startUptime
220+
let elapsed = max(0, nowUptime - startUptime)
221+
return Int64((elapsed * Double(effectiveFps)).rounded(.down))
222+
}
223+
224+
private func monotonicTimestampValue(for candidateTimestampValue: Int64) -> Int64 {
225+
if candidateTimestampValue <= lastTimestampValue {
223226
return lastTimestampValue + 1
224227
}
225-
return timestampValue
228+
return candidateTimestampValue
226229
}
227230

228231
private func shouldStop() -> Bool {
@@ -269,13 +272,10 @@ extension RunnerTests {
269272
#if AGENT_DEVICE_RUNNER_UNIT_TESTS
270273
extension RunnerTests.ScreenRecorder {
271274
@discardableResult
272-
func allocateTimestampForTesting(_ requestedTimestampValue: Int64) -> Int64 {
275+
func allocateTimestampForTesting(_ candidateTimestampValue: Int64) -> Int64 {
273276
lock.lock()
274277
defer { lock.unlock() }
275-
let nowUptime = ProcessInfo.processInfo.systemUptime
276-
recordingStartUptime =
277-
nowUptime - Double(requestedTimestampValue) / Double(effectiveFps)
278-
let allocatedTimestamp = timestampValue(for: nowUptime)
278+
let allocatedTimestamp = monotonicTimestampValue(for: candidateTimestampValue)
279279
lastTimestampValue = allocatedTimestamp
280280
return allocatedTimestamp
281281
}

0 commit comments

Comments
 (0)