diff --git a/Sources/AblyChat/RoomLifecycleManager.swift b/Sources/AblyChat/RoomLifecycleManager.swift index 4ea178f2..867f6d3c 100644 --- a/Sources/AblyChat/RoomLifecycleManager.swift +++ b/Sources/AblyChat/RoomLifecycleManager.swift @@ -29,8 +29,8 @@ internal actor RoomLifecycleManager { private let clock: SimpleClock private let contributors: [Contributor] - internal init(contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) { - self.init( + internal init(contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) async { + await self.init( current: nil, contributors: contributors, logger: logger, @@ -39,8 +39,8 @@ internal actor RoomLifecycleManager { } #if DEBUG - internal init(testsOnly_current current: RoomLifecycle? = nil, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) { - self.init( + internal init(testsOnly_current current: RoomLifecycle? = nil, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) async { + await self.init( current: current, contributors: contributors, logger: logger, @@ -49,7 +49,7 @@ internal actor RoomLifecycleManager { } #endif - private init(current: RoomLifecycle?, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) { + private init(current: RoomLifecycle?, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) async { self.current = current ?? .initialized self.contributors = contributors self.logger = logger diff --git a/Tests/AblyChatTests/RoomLifecycleManagerTests.swift b/Tests/AblyChatTests/RoomLifecycleManagerTests.swift index 312e85d4..f632fb62 100644 --- a/Tests/AblyChatTests/RoomLifecycleManagerTests.swift +++ b/Tests/AblyChatTests/RoomLifecycleManagerTests.swift @@ -31,8 +31,8 @@ struct RoomLifecycleManagerTests { forTestingWhatHappensWhenCurrentlyIn current: RoomLifecycle? = nil, contributors: [RoomLifecycleManager.Contributor] = [], clock: SimpleClock = MockSimpleClock() - ) -> RoomLifecycleManager { - .init(testsOnly_current: current, contributors: contributors, logger: TestLogger(), clock: clock) + ) async -> RoomLifecycleManager { + await .init(testsOnly_current: current, contributors: contributors, logger: TestLogger(), clock: clock) } private func createContributor( @@ -50,14 +50,14 @@ struct RoomLifecycleManagerTests { // @spec CHA-RS3 @Test func current_startsAsInitialized() async { - let manager = createManager() + let manager = await createManager() #expect(await manager.current == .initialized) } @Test func error_startsAsNil() async { - let manager = createManager() + let manager = await createManager() #expect(await manager.error == nil) } @@ -69,7 +69,7 @@ struct RoomLifecycleManagerTests { func attach_whenAlreadyAttached() async throws { // Given: A RoomLifecycleManager in the ATTACHED state let contributor = createContributor() - let manager = createManager(forTestingWhatHappensWhenCurrentlyIn: .attached, contributors: [contributor]) + let manager = await createManager(forTestingWhatHappensWhenCurrentlyIn: .attached, contributors: [contributor]) // When: `performAttachOperation()` is called on the lifecycle manager try await manager.performAttachOperation() @@ -82,7 +82,7 @@ struct RoomLifecycleManagerTests { @Test func attach_whenReleasing() async throws { // Given: A RoomLifecycleManager in the RELEASING state - let manager = createManager(forTestingWhatHappensWhenCurrentlyIn: .releasing) + let manager = await createManager(forTestingWhatHappensWhenCurrentlyIn: .releasing) // When: `performAttachOperation()` is called on the lifecycle manager // Then: It throws a roomIsReleasing error @@ -97,7 +97,7 @@ struct RoomLifecycleManagerTests { @Test func attach_whenReleased() async throws { // Given: A RoomLifecycleManager in the RELEASED state - let manager = createManager(forTestingWhatHappensWhenCurrentlyIn: .released) + let manager = await createManager(forTestingWhatHappensWhenCurrentlyIn: .released) // When: `performAttachOperation()` is called on the lifecycle manager // Then: It throws a roomIsReleased error @@ -114,7 +114,7 @@ struct RoomLifecycleManagerTests { // Given: A RoomLifecycleManager, with a contributor on whom calling `attach()` will not complete until after the "Then" part of this test (the motivation for this is to suppress the room from transitioning to ATTACHED, so that we can assert its current state as being ATTACHING) let contributorAttachOperation = SignallableChannelOperation() - let manager = createManager(contributors: [createContributor(attachBehavior: contributorAttachOperation.behavior)]) + let manager = await createManager(contributors: [createContributor(attachBehavior: contributorAttachOperation.behavior)]) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let statusChange = statusChangeSubscription.first { _ in true } @@ -136,7 +136,7 @@ struct RoomLifecycleManagerTests { func attach_attachesAllContributors_andWhenTheyAllAttachSuccessfully_transitionsToAttached() async throws { // Given: A RoomLifecycleManager, all of whose contributors’ calls to `attach` succeed let contributors = (1 ... 3).map { _ in createContributor(attachBehavior: .complete(.success)) } - let manager = createManager(contributors: contributors) + let manager = await createManager(contributors: contributors) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let attachedStatusChange = statusChangeSubscription.first { $0.current == .attached } @@ -168,7 +168,7 @@ struct RoomLifecycleManagerTests { } } - let manager = createManager(contributors: contributors) + let manager = await createManager(contributors: contributors) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let maybeSuspendedStatusChange = statusChangeSubscription.first { $0.current == .suspended } @@ -219,7 +219,7 @@ struct RoomLifecycleManagerTests { } } - let manager = createManager(contributors: contributors) + let manager = await createManager(contributors: contributors) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let maybeFailedStatusChange = statusChangeSubscription.first { $0.current == .failed } @@ -270,7 +270,7 @@ struct RoomLifecycleManagerTests { ), ] - let manager = createManager(contributors: contributors) + let manager = await createManager(contributors: contributors) // When: `performAttachOperation()` is called on the lifecycle manager try? await manager.performAttachOperation() @@ -312,7 +312,7 @@ struct RoomLifecycleManagerTests { ), ] - let manager = createManager(contributors: contributors) + let manager = await createManager(contributors: contributors) // When: `performAttachOperation()` is called on the lifecycle manager try? await manager.performAttachOperation() @@ -328,7 +328,7 @@ struct RoomLifecycleManagerTests { func detach_whenAlreadyDetached() async throws { // Given: A RoomLifecycleManager in the DETACHED state let contributor = createContributor() - let manager = createManager(forTestingWhatHappensWhenCurrentlyIn: .detached, contributors: [contributor]) + let manager = await createManager(forTestingWhatHappensWhenCurrentlyIn: .detached, contributors: [contributor]) // When: `performDetachOperation()` is called on the lifecycle manager try await manager.performDetachOperation() @@ -341,7 +341,7 @@ struct RoomLifecycleManagerTests { @Test func detach_whenReleasing() async throws { // Given: A RoomLifecycleManager in the RELEASING state - let manager = createManager(forTestingWhatHappensWhenCurrentlyIn: .releasing) + let manager = await createManager(forTestingWhatHappensWhenCurrentlyIn: .releasing) // When: `performDetachOperation()` is called on the lifecycle manager // Then: It throws a roomIsReleasing error @@ -356,7 +356,7 @@ struct RoomLifecycleManagerTests { @Test func detach_whenReleased() async throws { // Given: A RoomLifecycleManager in the RELEASED state - let manager = createManager(forTestingWhatHappensWhenCurrentlyIn: .released) + let manager = await createManager(forTestingWhatHappensWhenCurrentlyIn: .released) // When: `performAttachOperation()` is called on the lifecycle manager // Then: It throws a roomIsReleased error @@ -371,7 +371,7 @@ struct RoomLifecycleManagerTests { @Test func detach_whenFailed() async throws { // Given: A RoomLifecycleManager in the FAILED state - let manager = createManager(forTestingWhatHappensWhenCurrentlyIn: .failed) + let manager = await createManager(forTestingWhatHappensWhenCurrentlyIn: .failed) // When: `performAttachOperation()` is called on the lifecycle manager // Then: It throws a roomInFailedState error @@ -388,7 +388,7 @@ struct RoomLifecycleManagerTests { // Given: A RoomLifecycleManager, with a contributor on whom calling `detach()` will not complete until after the "Then" part of this test (the motivation for this is to suppress the room from transitioning to DETACHED, so that we can assert its current state as being DETACHING) let contributorDetachOperation = SignallableChannelOperation() - let manager = createManager(contributors: [createContributor(detachBehavior: contributorDetachOperation.behavior)]) + let manager = await createManager(contributors: [createContributor(detachBehavior: contributorDetachOperation.behavior)]) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let statusChange = statusChangeSubscription.first { _ in true } @@ -409,7 +409,7 @@ struct RoomLifecycleManagerTests { func detach_detachesAllContributors_andWhenTheyAllDetachSuccessfully_transitionsToDetached() async throws { // Given: A RoomLifecycleManager, all of whose contributors’ calls to `detach` succeed let contributors = (1 ... 3).map { _ in createContributor(detachBehavior: .complete(.success)) } - let manager = createManager(contributors: contributors) + let manager = await createManager(contributors: contributors) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let detachedStatusChange = statusChangeSubscription.first { $0.current == .detached } @@ -446,7 +446,7 @@ struct RoomLifecycleManagerTests { createContributor(feature: .typing, detachBehavior: .success), ] - let manager = createManager(contributors: contributors) + let manager = await createManager(contributors: contributors) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let maybeFailedStatusChange = statusChangeSubscription.first { $0.current == .failed } @@ -493,7 +493,7 @@ struct RoomLifecycleManagerTests { let contributor = createContributor(initialState: .attached, detachBehavior: .fromFunction(detachImpl)) let clock = MockSimpleClock() - let manager = createManager(contributors: [contributor], clock: clock) + let manager = await createManager(contributors: [contributor], clock: clock) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let asyncLetStatusChanges = Array(statusChangeSubscription.prefix(2)) @@ -517,7 +517,7 @@ struct RoomLifecycleManagerTests { func release_whenAlreadyReleased() async { // Given: A RoomLifecycleManager in the RELEASED state let contributor = createContributor() - let manager = createManager(forTestingWhatHappensWhenCurrentlyIn: .released, contributors: [contributor]) + let manager = await createManager(forTestingWhatHappensWhenCurrentlyIn: .released, contributors: [contributor]) // When: `performReleaseOperation()` is called on the lifecycle manager await manager.performReleaseOperation() @@ -531,7 +531,7 @@ struct RoomLifecycleManagerTests { func release_whenDetached() async throws { // Given: A RoomLifecycleManager in the DETACHED state let contributor = createContributor() - let manager = createManager(forTestingWhatHappensWhenCurrentlyIn: .detached, contributors: [contributor]) + let manager = await createManager(forTestingWhatHappensWhenCurrentlyIn: .detached, contributors: [contributor]) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let statusChange = statusChangeSubscription.first { _ in true } @@ -551,7 +551,7 @@ struct RoomLifecycleManagerTests { // Given: A RoomLifecycleManager, with a contributor on whom calling `detach()` will not complete until after the "Then" part of this test (the motivation for this is to suppress the room from transitioning to RELEASED, so that we can assert its current state as being RELEASING) let contributorDetachOperation = SignallableChannelOperation() - let manager = createManager(contributors: [createContributor(detachBehavior: contributorDetachOperation.behavior)]) + let manager = await createManager(contributors: [createContributor(detachBehavior: contributorDetachOperation.behavior)]) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let statusChange = statusChangeSubscription.first { _ in true } @@ -580,7 +580,7 @@ struct RoomLifecycleManagerTests { createContributor(initialState: .detached /* arbitrary non-FAILED */, detachBehavior: .complete(.success)), ] - let manager = createManager(contributors: contributors) + let manager = await createManager(contributors: contributors) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let releasedStatusChange = statusChangeSubscription.first { $0.current == .released } @@ -620,7 +620,7 @@ struct RoomLifecycleManagerTests { let clock = MockSimpleClock() - let manager = createManager(contributors: [contributor], clock: clock) + let manager = await createManager(contributors: [contributor], clock: clock) // Then: When `performReleaseOperation()` is called on the manager await manager.performReleaseOperation() @@ -640,7 +640,7 @@ struct RoomLifecycleManagerTests { let clock = MockSimpleClock() - let manager = createManager(contributors: [contributor], clock: clock) + let manager = await createManager(contributors: [contributor], clock: clock) let statusChangeSubscription = await manager.onChange(bufferingPolicy: .unbounded) async let releasedStatusChange = statusChangeSubscription.first { $0.current == .released }