Skip to content

Commit

Permalink
Introduce a wait to work around history not being “live”
Browse files Browse the repository at this point in the history
Resolves #167.
  • Loading branch information
lawrence-forooghian committed Dec 4, 2024
1 parent 25e3f41 commit 74cbbf4
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion Tests/AblyChatTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,36 @@ struct IntegrationTests {
#expect(rxMessageFromSubscription == txMessageAfterRxSubscribe)

// (7) Fetch historical messages from before subscribing, and check we get txMessageBeforeRxSubscribe
let rxMessagesBeforeSubscribing = try await rxMessageSubscription.getPreviousMessages(params: .init())

/*
TODO: This line should just be

let messages = try await rxMessageSubscription.getPreviousMessages(params: .init())

but sometimes `messages.items` is coming back empty. Andy said in
https://ably-real-time.slack.com/archives/C03JDBVM5MY/p1733220395208909
that

> new materialised history system doesn’t currently support “live”
> history (realtime implementation detail) - so we’re approximating the
> behaviour

and indicated that the right workaround for now is to introduce a
wait. So we retry the fetching of history until we get a non-empty
result.

Revert this (https://github.com/ably/ably-chat-swift/issues/175) once it’s fixed in Realtime.
*/
let rxMessagesBeforeSubscribing = try await {
while true {
let messages = try await rxMessageSubscription.getPreviousMessages(params: .init())
if !messages.items.isEmpty {
return messages
}
// Wait 1 second before retrying the history fetch
try await Task.sleep(nanoseconds: NSEC_PER_SEC)
}
}()
try #require(rxMessagesBeforeSubscribing.items.count == 1)
#expect(rxMessagesBeforeSubscribing.items[0] == txMessageBeforeRxSubscribe)

Expand Down

0 comments on commit 74cbbf4

Please sign in to comment.