Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions ios/Tests/GutenbergKitTests/Media/MediaUploadServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ struct MediaUploadServerTests {
// those reads: a file admitted for processing was forwarded unprocessed. The
// host dropping it before the request is the same condition, deterministically.
let mockUploader = MockInternalMediaClient()
var delegate: TranscodingProcessor? = TranscodingProcessor()
var delegate: ResizingProcessor? = ResizingProcessor()
weak let weakDelegate = delegate
let server = try await MediaUploadServer.start(processor: delegate, internalClient: mockUploader)
defer { server.stop() }
Expand Down Expand Up @@ -1106,25 +1106,35 @@ private final class RecordingUploader: MediaUploader, @unchecked Sendable {

/// An uploader whose delivery fails terminally, as one would after exhausting its own
/// post-process recovery and force-deleting the orphan.
private final class ThrowingUploader: MediaUploader, @unchecked Sendable {
private final class ThrowingUploader: MediaUploader {
struct Failure: Error {}

func upload(_ upload: MediaUpload) async throws -> Data {
throw Failure()
}
}

/// A delegate that transcodes, used to check the server holds it across the whole
/// request rather than re-reading a reference the host may have dropped.
private final class TranscodingProcessor: MediaProcessor, @unchecked Sendable {
/// A processor that declines every file by metadata.
private final class DecliningProcessor: MediaProcessor {
func handlesFile(ofType mimeType: String, named filename: String) -> Bool {
true
false
}
}

private final class MockProcessor: MediaProcessor, @unchecked Sendable {
private let lock = NSLock()
private var _processFileCalled = false
private var _lastMimeType: String?

var processFileCalled: Bool { lock.withLock { _processFileCalled } }
var lastMimeType: String? { lock.withLock { _lastMimeType } }

func processFile(at url: URL, mimeType: String, filename: String) async throws -> ProcessedProxyFile {
let processed = FileManager.default.temporaryDirectory.appendingPathComponent("clip.mp4")
try? Data("transcoded".utf8).write(to: processed)
return .processed(processed, mimeType: "video/mp4", filename: "clip.mp4")
lock.withLock {
_processFileCalled = true
_lastMimeType = mimeType
}
return .original
}
}

Expand Down
Loading