[api-upload-refactor] Convert API to an actor, drop @MainActor
- API: @MainActor struct -> actor. certData/certPassword/persistConnectionDelay move from static var (data race) to actor-isolated instance state - setupCertificationRequest -> setupCertification; add setPersistConnectionDelay - add internal init(testConfiguration:) seam; makeSession() helper picks test / cert-delegate / shared session - URLSessionDelegateHandler: final + @unchecked Sendable, immutable let certs, no @MainActor; challenge logic unchanged - getIdentity(): remove as! SecIdentity, extract via typed Unmanaged bridging - delete unused Result enum and defaultParams - APIActorTests: actor conformance, delay round-trip, per-instance cert state
This commit is contained in:
26
Tests/LCEssentialsTests/APIActorTests.swift
Normal file
26
Tests/LCEssentialsTests/APIActorTests.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
import XCTest
|
||||
@testable import LCEssentials
|
||||
|
||||
final class APIActorTests: XCTestCase {
|
||||
|
||||
func testAPIIsAnActorNotMainActorBound() async {
|
||||
let isActor = (API.shared as Any) is any Actor
|
||||
XCTAssertTrue(isActor, "API must be an actor so callers are not forced onto the main thread")
|
||||
}
|
||||
|
||||
func testPersistConnectionDelayRoundTrips() async {
|
||||
let api = API(testConfiguration: .ephemeral)
|
||||
await api.setPersistConnectionDelay(9)
|
||||
let value = await api.persistConnectionDelay
|
||||
XCTAssertEqual(value, 9)
|
||||
}
|
||||
|
||||
func testIsolatedTestInstanceDoesNotTouchSharedCertState() async {
|
||||
let api = API(testConfiguration: .ephemeral)
|
||||
await api.setupCertification(certData: Data([0x01, 0x02]), password: "pw")
|
||||
let sharedHasCert = await API.shared.hasClientCertificateConfigured
|
||||
let instanceHasCert = await api.hasClientCertificateConfigured
|
||||
XCTAssertFalse(sharedHasCert)
|
||||
XCTAssertTrue(instanceHasCert)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user