From ad529b10f442eecdc33f5517a9ab9c7cc9d24449 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Tue, 1 Oct 2024 17:59:32 -0300 Subject: [PATCH] Rename RoomLifecycleManager.current It was called `current` in 25e5052 to match the naming used in the public API at the time. Post-64c0315, calling it `status` makes more sense. --- Sources/AblyChat/RoomLifecycleManager.swift | 30 +++++++++---------- .../DefaultRoomLifecycleTests.swift | 2 +- .../RoomLifecycleManagerTests.swift | 28 ++++++++--------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Sources/AblyChat/RoomLifecycleManager.swift b/Sources/AblyChat/RoomLifecycleManager.swift index eb8f3730..390cde65 100644 --- a/Sources/AblyChat/RoomLifecycleManager.swift +++ b/Sources/AblyChat/RoomLifecycleManager.swift @@ -22,7 +22,7 @@ internal actor RoomLifecycleManager { internal var channel: Channel } - internal private(set) var current: RoomStatus + internal private(set) var status: RoomStatus internal private(set) var error: ARTErrorInfo? private let logger: InternalLogger @@ -35,7 +35,7 @@ internal actor RoomLifecycleManager { clock: SimpleClock ) { self.init( - current: nil, + status: nil, contributors: contributors, logger: logger, clock: clock @@ -44,13 +44,13 @@ internal actor RoomLifecycleManager { #if DEBUG internal init( - testsOnly_current current: RoomStatus? = nil, + testsOnly_status status: RoomStatus? = nil, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock ) { self.init( - current: current, + status: status, contributors: contributors, logger: logger, clock: clock @@ -59,12 +59,12 @@ internal actor RoomLifecycleManager { #endif private init( - current: RoomStatus?, + status: RoomStatus?, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock ) { - self.current = current ?? .initialized + self.status = status ?? .initialized self.contributors = contributors self.logger = logger self.clock = clock @@ -79,13 +79,13 @@ internal actor RoomLifecycleManager { return subscription } - /// Updates ``current`` and ``error`` and emits a status change event. + /// Updates ``status`` and ``error`` and emits a status change event. private func changeStatus(to new: RoomStatus, error: ARTErrorInfo? = nil) { - logger.log(message: "Transitioning from \(current) to \(new), error \(String(describing: error))", level: .info) - let previous = current - current = new + logger.log(message: "Transitioning from \(status) to \(new), error \(String(describing: error))", level: .info) + let previous = status + status = new self.error = error - let statusChange = RoomStatusChange(current: current, previous: previous, error: error) + let statusChange = RoomStatusChange(current: status, previous: previous, error: error) emitStatusChange(statusChange) } @@ -97,7 +97,7 @@ internal actor RoomLifecycleManager { /// Implements CHA-RL1’s `ATTACH` operation. internal func performAttachOperation() async throws { - switch current { + switch status { case .attached: // CHA-RL1a return @@ -171,7 +171,7 @@ internal actor RoomLifecycleManager { /// Implements CHA-RL2’s DETACH operation. internal func performDetachOperation() async throws { - switch current { + switch status { case .detached: // CHA-RL2a return @@ -217,7 +217,7 @@ internal actor RoomLifecycleManager { } // This check is CHA-RL2h2 - if current != .failed { + if status != .failed { changeStatus(to: .failed, error: error) } default: @@ -250,7 +250,7 @@ internal actor RoomLifecycleManager { /// Implementes CHA-RL3’s RELEASE operation. internal func performReleaseOperation() async { - switch current { + switch status { case .released: // CHA-RL3a return diff --git a/Tests/AblyChatTests/DefaultRoomLifecycleTests.swift b/Tests/AblyChatTests/DefaultRoomLifecycleTests.swift index efb8b4e3..a3d3f065 100644 --- a/Tests/AblyChatTests/DefaultRoomLifecycleTests.swift +++ b/Tests/AblyChatTests/DefaultRoomLifecycleTests.swift @@ -3,7 +3,7 @@ import Testing struct DefaultRoomLifecycleTests { @Test - func current_startsAsInitialized() async { + func status_startsAsInitialized() async { let lifecycle = DefaultRoomLifecycle(logger: TestLogger()) #expect(await lifecycle.status == .initialized) } diff --git a/Tests/AblyChatTests/RoomLifecycleManagerTests.swift b/Tests/AblyChatTests/RoomLifecycleManagerTests.swift index 5e57ec50..54b33079 100644 --- a/Tests/AblyChatTests/RoomLifecycleManagerTests.swift +++ b/Tests/AblyChatTests/RoomLifecycleManagerTests.swift @@ -28,12 +28,12 @@ struct RoomLifecycleManagerTests { } private func createManager( - forTestingWhatHappensWhenCurrentlyIn current: RoomStatus? = nil, + forTestingWhatHappensWhenCurrentlyIn status: RoomStatus? = nil, contributors: [RoomLifecycleManager.Contributor] = [], clock: SimpleClock = MockSimpleClock() ) -> RoomLifecycleManager { .init( - testsOnly_current: current, + testsOnly_status: status, contributors: contributors, logger: TestLogger(), clock: clock @@ -61,10 +61,10 @@ struct RoomLifecycleManagerTests { // @spec CHA-RS2a // @spec CHA-RS3 @Test - func current_startsAsInitialized() async { + func status_startsAsInitialized() async { let manager = createManager() - #expect(await manager.current == .initialized) + #expect(await manager.status == .initialized) } @Test @@ -136,7 +136,7 @@ struct RoomLifecycleManagerTests { // Then: It emits a status change to ATTACHING, and its current status is ATTACHING #expect(try #require(await statusChange).current == .attaching) - #expect(await manager.current == .attaching) + #expect(await manager.status == .attaching) // Post-test: Now that we’ve seen the ATTACHING status, allow the contributor `attach` call to complete contributorAttachOperation.complete(result: .success) @@ -162,7 +162,7 @@ struct RoomLifecycleManagerTests { } _ = try #require(await attachedStatusChange, "Expected status change to ATTACHED") - try #require(await manager.current == .attached) + try #require(await manager.status == .attached) } // @spec CHA-RL1h2 @@ -195,7 +195,7 @@ struct RoomLifecycleManagerTests { // 3. the room attach operation fails with this same error let suspendedStatusChange = try #require(await maybeSuspendedStatusChange) - #expect(await manager.current == .suspended) + #expect(await manager.status == .suspended) var roomAttachError: Error? do { @@ -245,7 +245,7 @@ struct RoomLifecycleManagerTests { // 3. the room attach operation fails with this same error let failedStatusChange = try #require(await maybeFailedStatusChange) - #expect(await manager.current == .failed) + #expect(await manager.status == .failed) var roomAttachError: Error? do { @@ -409,7 +409,7 @@ struct RoomLifecycleManagerTests { // Then: It emits a status change to DETACHING, and its current status is DETACHING #expect(try #require(await statusChange).current == .detaching) - #expect(await manager.current == .detaching) + #expect(await manager.status == .detaching) // Post-test: Now that we’ve seen the DETACHING status, allow the contributor `detach` call to complete contributorDetachOperation.complete(result: .success) @@ -435,7 +435,7 @@ struct RoomLifecycleManagerTests { } _ = try #require(await detachedStatusChange, "Expected status change to DETACHED") - #expect(await manager.current == .detached) + #expect(await manager.status == .detached) } // @spec CHA-RL2h1 @@ -553,7 +553,7 @@ struct RoomLifecycleManagerTests { // Then: The room release operation succeeds, the room transitions to RELEASED, and no attempt is made to detach a contributor (which we’ll consider as satisfying the spec’s requirement that the transition be "immediate") #expect(try #require(await statusChange).current == .released) - #expect(await manager.current == .released) + #expect(await manager.status == .released) #expect(await contributor.channel.detachCallCount == 0) } @@ -572,7 +572,7 @@ struct RoomLifecycleManagerTests { // Then: It emits a status change to RELEASING, and its current status is RELEASING #expect(try #require(await statusChange).current == .releasing) - #expect(await manager.current == .releasing) + #expect(await manager.status == .releasing) // Post-test: Now that we’ve seen the RELEASING status, allow the contributor `detach` call to complete contributorDetachOperation.complete(result: .success) @@ -614,7 +614,7 @@ struct RoomLifecycleManagerTests { _ = await releasedStatusChange - #expect(await manager.current == .released) + #expect(await manager.status == .released) } // @spec CHA-RL3f @@ -673,6 +673,6 @@ struct RoomLifecycleManagerTests { _ = await releasedStatusChange - #expect(await manager.current == .released) + #expect(await manager.status == .released) } }