From d7010d5271d42c28a542bf0d41a285ed47bdaa9e Mon Sep 17 00:00:00 2001 From: shum Date: Thu, 19 Feb 2026 07:39:50 +0000 Subject: [PATCH] core: fix flaky testDisableCIExpirationOnlyForOneUser for cleanup manager timing --- tests/ChatTests/Direct.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/ChatTests/Direct.hs b/tests/ChatTests/Direct.hs index ee4a8fd9f7..5b9edd01ec 100644 --- a/tests/ChatTests/Direct.hs +++ b/tests/ChatTests/Direct.hs @@ -2358,10 +2358,8 @@ testDisableCIExpirationOnlyForOneUser ps = do alice #$> ("/_get chat @6 count=100", chat, chatFeatures <> [(1, "alisa 1"), (0, "alisa 2")]) - threadDelay 2000000 - - -- second user messages are deleted - alice #$> ("/_get chat @6 count=100", chat, [(1,"chat banner")]) + -- second user messages are deleted (cleanup manager interval = 500ms, ttl = 1s) + waitUntilExpired alice "@6" [(1, "chat banner")] withTestChatCfg ps cfg "alice" $ \alice -> do alice <## "subscribed 1 connections on server localhost" @@ -2377,12 +2375,17 @@ testDisableCIExpirationOnlyForOneUser ps = do alice #$> ("/_get chat @6 count=100", chat, [(1,"chat banner"), (1, "alisa 3"), (0, "alisa 4")]) - threadDelay 2000000 - - -- second user messages are deleted - alice #$> ("/_get chat @6 count=100", chat, [(1,"chat banner")]) + -- second user messages are deleted (cleanup manager interval = 500ms, ttl = 1s) + waitUntilExpired alice "@6" [(1, "chat banner")] where cfg = testCfg {initialCleanupManagerDelay = 0, cleanupManagerStepDelay = 0, ciExpirationInterval = 500000} + waitUntilExpired cc chatRef expected = do + let go 0 = cc #$> ("/_get chat " <> chatRef <> " count=100", chat, expected) + go n = do + cc ##> ("/_get chat " <> chatRef <> " count=100") + r <- chat <$> getTermLine cc + if r == expected then pure () else threadDelay 500000 >> go (n - 1) + go (10 :: Int) testUsersTimedMessages :: HasCallStack => TestParams -> IO () testUsersTimedMessages ps' = do