Skip to content

Commit

Permalink
Fill in previously-unspecified wait durations
Browse files Browse the repository at this point in the history
This are now specified. Taken from spec version 8ff947d.
  • Loading branch information
lawrence-forooghian committed Nov 19, 2024
1 parent c0ddfd0 commit a04d20c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions Sources/AblyChat/RoomLifecycleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,9 @@ internal actor DefaultRoomLifecycleManager<Contributor: RoomLifecycleContributor
// CHA-RL2h3: Retry until detach succeeds, with a pause before each attempt
while true {
do {
logger.log(message: "Will attempt to detach non-failed contributor \(contributor) in 1s.", level: .info)
// TODO: what's the correct wait time? (https://github.com/ably/specification/pull/200#discussion_r1763799223)
try await clock.sleep(timeInterval: 1)
let waitDuration = 0.25
logger.log(message: "Will attempt to detach non-failed contributor \(contributor) in \(waitDuration)s.", level: .info)
try await clock.sleep(timeInterval: waitDuration)
logger.log(message: "Detaching non-failed contributor \(contributor)", level: .info)
try await contributor.channel.detach()
break
Expand Down Expand Up @@ -968,11 +968,11 @@ internal actor DefaultRoomLifecycleManager<Contributor: RoomLifecycleContributor
break
} catch {
// CHA-RL3f: Retry until detach succeeds, with a pause before each attempt
logger.log(message: "Failed to detach contributor \(contributor), error \(error). Will retry in 1s.", level: .info)
let waitDuration = 0.25
logger.log(message: "Failed to detach contributor \(contributor), error \(error). Will retry in \(waitDuration)s.", level: .info)
// TODO: Make this not trap in the case where the Task is cancelled (as part of the broader https://github.com/ably-labs/ably-chat-swift/issues/29 for handling task cancellation)
// TODO: what's the correct wait time? (https://github.com/ably/specification/pull/200#discussion_r1763822207)
// swiftlint:disable:next force_try
try! await clock.sleep(timeInterval: 1)
try! await clock.sleep(timeInterval: waitDuration)
// Loop repeats
}
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/AblyChatTests/DefaultRoomLifecycleManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,11 @@ struct DefaultRoomLifecycleManagerTests {
// When: `performDetachOperation()` is called on the manager
try await manager.performDetachOperation()

// Then: It attempts to detach the channel 3 times, waiting 1s between each attempt, the room transitions from DETACHING to DETACHED with no status updates in between, and the call to `performDetachOperation()` succeeds
// Then: It attempts to detach the channel 3 times, waiting 250ms between each attempt, the room transitions from DETACHING to DETACHED with no status updates in between, and the call to `performDetachOperation()` succeeds
#expect(await contributor.channel.detachCallCount == 3)

// We use "did it call clock.sleep(…)?" as a good-enough proxy for the question "did it wait for the right amount of time at the right moment?"
#expect(await clock.sleepCallArguments == Array(repeating: 1, count: 2))
#expect(await clock.sleepCallArguments == Array(repeating: 0.25, count: 2))

#expect(await asyncLetStatusChanges.map(\.current) == [.detaching, .detached])
}
Expand Down Expand Up @@ -845,11 +845,11 @@ struct DefaultRoomLifecycleManagerTests {
// Then: When `performReleaseOperation()` is called on the manager
await manager.performReleaseOperation()

// It: calls `detach()` on the channel 3 times, with a 1s pause between each attempt, and the call to `performReleaseOperation` completes
// It: calls `detach()` on the channel 3 times, with a 0.25s pause between each attempt, and the call to `performReleaseOperation` completes
#expect(await contributor.channel.detachCallCount == 3)

// We use "did it call clock.sleep(…)?" as a good-enough proxy for the question "did it wait for the right amount of time at the right moment?"
#expect(await clock.sleepCallArguments == Array(repeating: 1, count: 2))
#expect(await clock.sleepCallArguments == Array(repeating: 0.25, count: 2))
}

// @specOneOf(2/2) CHA-RL3e - Tests that this spec point suppresses CHA-RL3f retries
Expand All @@ -870,13 +870,13 @@ struct DefaultRoomLifecycleManagerTests {

// Then:
// - it calls `detach()` precisely once on the contributor (that is, it does not retry)
// - it waits 1s (TODO: confirm my interpretation of CHA-RL3f, which is that the wait still happens, but is not followed by a retry; have asked in https://github.com/ably/specification/pull/200/files#r1765372854)
// - it waits 0.25s (TODO: confirm my interpretation of CHA-RL3f, which is that the wait still happens, but is not followed by a retry; have asked in https://github.com/ably/specification/pull/200/files#r1765372854)
// - the room transitions to RELEASED
// - the call to `performReleaseOperation()` completes
#expect(await contributor.channel.detachCallCount == 1)

// We use "did it call clock.sleep(…)?" as a good-enough proxy for the question "did it wait for the right amount of time at the right moment?"
#expect(await clock.sleepCallArguments == [1])
#expect(await clock.sleepCallArguments == [0.25])

_ = await releasedStatusChange

Expand Down

0 comments on commit a04d20c

Please sign in to comment.