diff --git a/Sources/AblyChat/RoomLifecycleManager.swift b/Sources/AblyChat/RoomLifecycleManager.swift index 845de196..84c656e3 100644 --- a/Sources/AblyChat/RoomLifecycleManager.swift +++ b/Sources/AblyChat/RoomLifecycleManager.swift @@ -13,15 +13,16 @@ internal protocol RoomLifecycleContributorChannel: Sendable { var errorReason: ARTErrorInfo? { get async } } -internal actor RoomLifecycleManager { - /// A realtime channel that contributes to the room lifecycle. - internal struct Contributor { - /// The room feature that this contributor corresponds to. Used only for choosing which error to throw when a contributor operation fails. - internal var feature: RoomFeature +/// A realtime channel that contributes to the room lifecycle. +internal protocol RoomLifecycleContributor: Sendable { + associatedtype Channel: RoomLifecycleContributorChannel - internal var channel: Channel - } + /// The room feature that this contributor corresponds to. Used only for choosing which error to throw when a contributor operation fails. + var feature: RoomFeature { get } + var channel: Channel { get } +} +internal actor RoomLifecycleManager { internal private(set) var current: RoomLifecycle internal private(set) var error: ARTErrorInfo? diff --git a/Tests/AblyChatTests/Mocks/MockRoomLifecycleContributor.swift b/Tests/AblyChatTests/Mocks/MockRoomLifecycleContributor.swift new file mode 100644 index 00000000..d1a0d2af --- /dev/null +++ b/Tests/AblyChatTests/Mocks/MockRoomLifecycleContributor.swift @@ -0,0 +1,11 @@ +@testable import AblyChat + +actor MockRoomLifecycleContributor: RoomLifecycleContributor { + nonisolated let feature: RoomFeature + nonisolated let channel: MockRoomLifecycleContributorChannel + + init(feature: RoomFeature, channel: MockRoomLifecycleContributorChannel) { + self.feature = feature + self.channel = channel + } +} diff --git a/Tests/AblyChatTests/RoomLifecycleManagerTests.swift b/Tests/AblyChatTests/RoomLifecycleManagerTests.swift index e69f7118..e2c477b8 100644 --- a/Tests/AblyChatTests/RoomLifecycleManagerTests.swift +++ b/Tests/AblyChatTests/RoomLifecycleManagerTests.swift @@ -29,9 +29,9 @@ struct RoomLifecycleManagerTests { private func createManager( forTestingWhatHappensWhenCurrentlyIn current: RoomLifecycle? = nil, - contributors: [RoomLifecycleManager.Contributor] = [], + contributors: [MockRoomLifecycleContributor] = [], clock: SimpleClock = MockSimpleClock() - ) async -> RoomLifecycleManager { + ) async -> RoomLifecycleManager { await .init( testsOnly_current: current, contributors: contributors, @@ -45,7 +45,7 @@ struct RoomLifecycleManagerTests { feature: RoomFeature = .messages, // Arbitrarily chosen, its value only matters in test cases where we check which error is thrown attachBehavior: MockRoomLifecycleContributorChannel.AttachOrDetachBehavior? = nil, detachBehavior: MockRoomLifecycleContributorChannel.AttachOrDetachBehavior? = nil - ) -> RoomLifecycleManager.Contributor { + ) -> MockRoomLifecycleContributor { .init( feature: feature, channel: .init(