From e3a6720131052baf373dd1a60d2f7e31f013abad Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Fri, 15 May 2026 14:00:01 +0400 Subject: [PATCH] wip --- tests/ChatTests/Groups.hs | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/tests/ChatTests/Groups.hs b/tests/ChatTests/Groups.hs index 0ec63e1224..8517b2c29e 100644 --- a/tests/ChatTests/Groups.hs +++ b/tests/ChatTests/Groups.hs @@ -9945,29 +9945,14 @@ listRelayOwnStatuses cc = "SELECT group_id, relay_own_status FROM groups WHERE relay_own_status IS NOT NULL ORDER BY group_id" :: IO [(Int64, T.Text)] --- | Directly set relay_own_status on a relay's groups row (test surgery). -setRelayOwnStatus :: TestCC -> Int64 -> T.Text -> IO () -setRelayOwnStatus cc gId status = - withCCTransaction cc $ \db -> - DB.execute db "UPDATE groups SET relay_own_status = ? WHERE group_id = ?" (status, gId) - --- | Poll for a relay's row count with non-NULL relay_own_status to reach --- `expected` (e.g. after INFO cleanup removed a transient row). Up to 20 s. -waitForRelayGroupCount :: TestCC -> Int -> IO Int -waitForRelayGroupCount cc expected = loop (40 :: Int) - where - countRows = do - rows <- withCCTransaction cc $ \db -> - DB.query_ db "SELECT COUNT(*) FROM groups WHERE relay_own_status IS NOT NULL" :: IO [Only Int] - pure $ case rows of - [Only n] -> n +checkRelayGroupCount :: TestCC -> Int -> IO () +checkRelayGroupCount cc expected = do + rows <- withCCTransaction cc $ \db -> + DB.query_ db "SELECT COUNT(*) FROM groups WHERE relay_own_status IS NOT NULL" :: IO [Only Int] + let n = case rows of + [Only c] -> c _ -> 0 - loop 0 = countRows - loop n = do - c <- countRows - if c == expected - then pure c - else threadDelay 500000 >> loop (n - 1) + n `shouldBe` expected testRelayRefuseAfterLeave :: HasCallStack => TestParams -> IO () testRelayRefuseAfterLeave ps = @@ -10007,7 +9992,8 @@ testRelayRefuseAfterLeave ps = -- bob's transient row was created with relay_own_status='rejected'; -- after INFO arrives the cleanup arm deletes it. Original row 1 remains rejected. - _ <- waitForRelayGroupCount bob 1 + threadDelay 1000000 + checkRelayGroupCount bob 1 finalStatuses <- listRelayOwnStatuses bob finalStatuses `shouldBe` [(1, "rejected")] @@ -10096,7 +10082,8 @@ testRelayRefuseRaceConcurrentInvitations ps = alice <## "#team: group relays:" alice .<##. (" - relay id", ": invited") alice <## "#team: relay rejected, reason: RRRRejoinRefused" - void $ waitForRelayGroupCount bob 1 + threadDelay 1000000 + checkRelayGroupCount bob 1 -- second refusal alice ##> "/rm #team bob" @@ -10107,7 +10094,8 @@ testRelayRefuseRaceConcurrentInvitations ps = alice .<##. (" - relay id", ": invited") alice <## "#team: relay rejected, reason: RRRRejoinRefused" - _ <- waitForRelayGroupCount bob 1 + threadDelay 1000000 + checkRelayGroupCount bob 1 finalStatuses <- listRelayOwnStatuses bob finalStatuses `shouldBe` [(1, "rejected")]