Files
plezy/tvos/RunnerTests/AtmosProbeContractTests.swift
T
edde746 7e00de3ae9 fix(tvos): answer the Atmos probe start call exactly once
Hold the pending result in a one-shot latch fired by every terminal path,
including cancellation and deallocation. Stopping a probe mid-download
released the only strong reference and left the method call unanswered.
2026-07-27 17:44:52 +02:00

62 lines
1.8 KiB
Swift

import Foundation
import XCTest
@testable import Runner
final class AtmosProbeContractTests: XCTestCase {
func testCancelCompletesStartExactlyOnce() {
let completionDelivered = expectation(description: "start completion delivered")
let duplicateCompletion = expectation(description: "start completion delivered twice")
duplicateCompletion.isInverted = true
var invocationCount = 0
var probe: AsbarProbe? = makeProbe()
probe?.start { message in
invocationCount += 1
if invocationCount == 1 {
XCTAssertEqual(message, "cancelled")
completionDelivered.fulfill()
} else {
duplicateCompletion.fulfill()
}
}
probe?.cancel()
probe = nil
wait(for: [completionDelivered], timeout: 1)
wait(for: [duplicateCompletion], timeout: 1)
XCTAssertEqual(invocationCount, 1)
}
func testDeinitCompletesStartExactlyOnce() {
let completionDelivered = expectation(description: "start completion delivered")
let duplicateCompletion = expectation(description: "start completion delivered twice")
duplicateCompletion.isInverted = true
var invocationCount = 0
var probe: AsbarProbe? = makeProbe()
probe?.start { message in
invocationCount += 1
if invocationCount == 1 {
XCTAssertEqual(message, "cancelled")
completionDelivered.fulfill()
} else {
duplicateCompletion.fulfill()
}
}
probe = nil
wait(for: [completionDelivered], timeout: 1)
wait(for: [duplicateCompletion], timeout: 1)
XCTAssertEqual(invocationCount, 1)
}
private func makeProbe() -> AsbarProbe {
AsbarProbe(
source: URL(string: "http://127.0.0.1:1/probe.eac3")!,
regenerateFormatDescription: false,
sessionMode: .moviePlayback
)
}
}