Skip to content

Commit

Permalink
Rename RoomLifecycleManager.current
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lawrence-forooghian committed Oct 1, 2024
1 parent 64c0315 commit ad529b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
30 changes: 15 additions & 15 deletions Sources/AblyChat/RoomLifecycleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal actor RoomLifecycleManager<Channel: RoomLifecycleContributorChannel> {
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
Expand All @@ -35,7 +35,7 @@ internal actor RoomLifecycleManager<Channel: RoomLifecycleContributorChannel> {
clock: SimpleClock
) {
self.init(
current: nil,
status: nil,
contributors: contributors,
logger: logger,
clock: clock
Expand All @@ -44,13 +44,13 @@ internal actor RoomLifecycleManager<Channel: RoomLifecycleContributorChannel> {

#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
Expand All @@ -59,12 +59,12 @@ internal actor RoomLifecycleManager<Channel: RoomLifecycleContributorChannel> {
#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
Expand All @@ -79,13 +79,13 @@ internal actor RoomLifecycleManager<Channel: RoomLifecycleContributorChannel> {
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)
}

Expand All @@ -97,7 +97,7 @@ internal actor RoomLifecycleManager<Channel: RoomLifecycleContributorChannel> {

/// Implements CHA-RL1’s `ATTACH` operation.
internal func performAttachOperation() async throws {
switch current {
switch status {
case .attached:
// CHA-RL1a
return
Expand Down Expand Up @@ -171,7 +171,7 @@ internal actor RoomLifecycleManager<Channel: RoomLifecycleContributorChannel> {

/// Implements CHA-RL2’s DETACH operation.
internal func performDetachOperation() async throws {
switch current {
switch status {
case .detached:
// CHA-RL2a
return
Expand Down Expand Up @@ -217,7 +217,7 @@ internal actor RoomLifecycleManager<Channel: RoomLifecycleContributorChannel> {
}

// This check is CHA-RL2h2
if current != .failed {
if status != .failed {
changeStatus(to: .failed, error: error)
}
default:
Expand Down Expand Up @@ -250,7 +250,7 @@ internal actor RoomLifecycleManager<Channel: RoomLifecycleContributorChannel> {

/// Implementes CHA-RL3’s RELEASE operation.
internal func performReleaseOperation() async {
switch current {
switch status {
case .released:
// CHA-RL3a
return
Expand Down
2 changes: 1 addition & 1 deletion Tests/AblyChatTests/DefaultRoomLifecycleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
28 changes: 14 additions & 14 deletions Tests/AblyChatTests/RoomLifecycleManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ struct RoomLifecycleManagerTests {
}

private func createManager(
forTestingWhatHappensWhenCurrentlyIn current: RoomStatus? = nil,
forTestingWhatHappensWhenCurrentlyIn status: RoomStatus? = nil,
contributors: [RoomLifecycleManager<MockRoomLifecycleContributorChannel>.Contributor] = [],
clock: SimpleClock = MockSimpleClock()
) -> RoomLifecycleManager<MockRoomLifecycleContributorChannel> {
.init(
testsOnly_current: current,
testsOnly_status: status,
contributors: contributors,
logger: TestLogger(),
clock: clock
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down Expand Up @@ -614,7 +614,7 @@ struct RoomLifecycleManagerTests {

_ = await releasedStatusChange

#expect(await manager.current == .released)
#expect(await manager.status == .released)
}

// @spec CHA-RL3f
Expand Down Expand Up @@ -673,6 +673,6 @@ struct RoomLifecycleManagerTests {

_ = await releasedStatusChange

#expect(await manager.current == .released)
#expect(await manager.status == .released)
}
}

0 comments on commit ad529b1

Please sign in to comment.