Stop relying on a specific delay in cancellation test

This commit is contained in:
Sami Samhuri 2025-04-04 10:12:48 -07:00
parent 10c717ab99
commit 2f1b859a03
No known key found for this signature in database

View file

@ -296,11 +296,11 @@ final class ExportSessionTests: BaseTests {
@Test func test_export_cancellation() async throws { @Test func test_export_cancellation() async throws {
let sourceURL = resourceURL(named: "test-720p-h264-24fps.mov") let sourceURL = resourceURL(named: "test-720p-h264-24fps.mov")
let destinationURL💥 = makeTemporaryURL() let destinationURL💥 = makeTemporaryURL()
let subject = ExportSession()
let task = Task { let task = Task {
let sourceAsset = AVURLAsset(url: sourceURL, options: [ let sourceAsset = AVURLAsset(url: sourceURL, options: [
AVURLAssetPreferPreciseDurationAndTimingKey: true, AVURLAssetPreferPreciseDurationAndTimingKey: true,
]) ])
let subject = ExportSession()
try await subject.export( try await subject.export(
asset: sourceAsset, asset: sourceAsset,
video: .codec(.h264, width: 1280, height: 720), video: .codec(.h264, width: 1280, height: 720),
@ -309,8 +309,10 @@ final class ExportSessionTests: BaseTests {
) )
Issue.record("Task should be cancelled long before we get here") Issue.record("Task should be cancelled long before we get here")
} }
NSLog("Sleeping for 0.3s") NSLog("Waiting for encoding to begin...")
try await Task.sleep(for: .milliseconds(300)) for await progress in subject.progressStream where progress > 0 {
break
}
NSLog("Cancelling task") NSLog("Cancelling task")
task.cancel() task.cancel()
try? await task.value // Wait for task to complete try? await task.value // Wait for task to complete