Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a wait to work around history not being “live” #176

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading