From e7e5e3b8de5af56c5e4b8375a800bb9f06c83e11 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Wed, 4 Dec 2024 12:10:07 -0300 Subject: [PATCH] =?UTF-8?q?Introduce=20a=20wait=20to=20work=20around=20his?= =?UTF-8?q?tory=20not=20being=20=E2=80=9Clive=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (The integration tests are still failing, though, due to #169, but at least they’re now failing in a consistent manner.) Resolves #167. --- Tests/AblyChatTests/IntegrationTests.swift | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Tests/AblyChatTests/IntegrationTests.swift b/Tests/AblyChatTests/IntegrationTests.swift index abbfa2af..fa5b03d2 100644 --- a/Tests/AblyChatTests/IntegrationTests.swift +++ b/Tests/AblyChatTests/IntegrationTests.swift @@ -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)