57 lines
2.9 KiB
Swift
57 lines
2.9 KiB
Swift
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
import XCTest
|
|
|
|
final class CompanionStartupTests: XCTestCase {
|
|
@MainActor
|
|
func testBackgroundCompanionDoesNotRestoreMediaOrCreateRememberedStartupFiles() async throws {
|
|
let fixture = try StartupTests.Fixture()
|
|
defer { fixture.remove() }
|
|
let suite = "VCCCompanionStartup-" + UUID().uuidString
|
|
let defaults = UserDefaults(suiteName: suite)!
|
|
defer { defaults.removePersistentDomain(forName: suite) }
|
|
let model = MachineModel(diskStore: fixture.disks, displayDefaults: defaults,
|
|
inputStore: .init(url: fixture.support.appendingPathComponent("Input.json")),
|
|
startupStore: fixture.startup, restoreMediaOnLaunch: false)
|
|
// Give accidental queued startup work a chance to run. The assertion is
|
|
// against real authored media/state, not an internal implementation flag.
|
|
try await Task.sleep(nanoseconds: 100_000_000)
|
|
XCTAssertEqual(model.state, .empty)
|
|
XCTAssertFalse(model.busy)
|
|
XCTAssertTrue(model.disks.allSatisfy { !$0.mounted })
|
|
XCTAssertTrue(model.hardDisks.allSatisfy { !$0.mounted })
|
|
XCTAssertNil(model.systemROMURL)
|
|
XCTAssertFalse(model.tapeMounted)
|
|
XCTAssertFalse(FileManager.default.fileExists(atPath: fixture.support.path))
|
|
await withCheckedContinuation { continuation in model.shutdown { continuation.resume() } }
|
|
XCTAssertFalse(FileManager.default.fileExists(atPath: fixture.support.path),
|
|
"Quitting a service-only session must not save an empty startup configuration")
|
|
}
|
|
|
|
@MainActor
|
|
func testExplicitForegroundRestoreUsesOriginalStartupOnce() async throws {
|
|
let fixture = try StartupTests.Fixture()
|
|
defer { fixture.remove() }
|
|
let suite = "VCCCompanionForeground-" + UUID().uuidString
|
|
let defaults = UserDefaults(suiteName: suite)!
|
|
defer { defaults.removePersistentDomain(forName: suite) }
|
|
let model = MachineModel(diskStore: fixture.disks, displayDefaults: defaults,
|
|
inputStore: .init(url: fixture.support.appendingPathComponent("Input.json")),
|
|
startupStore: fixture.startup, restoreMediaOnLaunch: false)
|
|
model.restoreDeferredCompanionMachine()
|
|
for _ in 0..<1000 {
|
|
if !model.busy && !model.diskSaving { break }
|
|
try await Task.sleep(nanoseconds: 10_000_000)
|
|
}
|
|
XCTAssertFalse(model.busy)
|
|
XCTAssertNotNil(model.systemROMURL)
|
|
XCTAssertTrue(model.disks[0].mounted)
|
|
let assignments = try Data(contentsOf: fixture.disks.url)
|
|
let diskName = model.disks[0].name
|
|
model.restoreDeferredCompanionMachine()
|
|
try await Task.sleep(nanoseconds: 100_000_000)
|
|
XCTAssertEqual(model.disks[0].name, diskName)
|
|
XCTAssertEqual(try Data(contentsOf: fixture.disks.url), assignments)
|
|
await withCheckedContinuation { continuation in model.shutdown { continuation.resume() } }
|
|
}
|
|
}
|