TeraSessionGenerationTests.swift (2216B)
1 @testable import TeraApp 2 import XCTest 3 4 final class TeraSessionGenerationTests: XCTestCase { 5 func testSessionAdvancesWithoutChangingExistingDiagnosticValues() throws { 6 let first = try TeraSessionGeneration.initial.next() 7 let second = try first.next() 8 XCTAssertNotEqual(first, second) 9 XCTAssertEqual(first.diagnosticValue, "1") 10 XCTAssertEqual(second.diagnosticValue, "2") 11 let identity = TeraRuntimeOperationIdentity(generation: first, sequence: 7, kind: .startup) 12 XCTAssertEqual(identity.rawValue, "ios-runtime-1-7-startup") 13 XCTAssertEqual(TeraProjectionRevision(rawValue: UInt64.max).rawValue, UInt64.max) 14 } 15 16 func testExhaustionInvalidatesCallbacksAndNeverReusesAnEarlierSession() throws { 17 let beforeLast = TeraSessionGeneration(rawValue: UInt64.max - 1) 18 let last = try beforeLast.next() 19 XCTAssertEqual(last.diagnosticValue, String(UInt64.max)) 20 XCTAssertThrowsError(try last.next()) { error in 21 XCTAssertEqual(error as? TeraStateTransitionError, .generationOverflow) 22 } 23 let exhausted = last.invalidated() 24 XCTAssertNotEqual(exhausted, last) 25 XCTAssertNotEqual(exhausted, .initial) 26 XCTAssertFalse(exhausted.isActive) 27 XCTAssertEqual(exhausted.invalidated(), exhausted) 28 XCTAssertThrowsError(try exhausted.next()) 29 XCTAssertThrowsError(try exhausted.requireActive()) 30 } 31 } 32 33 extension TeraRuntimeClientTests { 34 func testRestartChangesSessionButPreservesDurableLaunchScope() async throws { 35 let harness = RuntimeHarness() 36 let client = TeraRuntimeClient(factory: harness.start) 37 let configuration = makeConfiguration(generation: "06") 38 let first = try await client.start(configuration: configuration) 39 let firstLifecycle = await client.lifecycle() 40 _ = try await client.stop() 41 let second = try await client.start(configuration: configuration) 42 let secondLifecycle = await client.lifecycle() 43 XCTAssertNotEqual(firstLifecycle, secondLifecycle) 44 XCTAssertEqual(first.identity, second.identity) 45 let launches = await harness.launchConfigurations() 46 XCTAssertEqual(launches, [configuration, configuration]) 47 _ = try await client.stop() 48 } 49 }