core: test forwarded message deduplication, mute terminal error (#3414)

This commit is contained in:
spaced4ndy
2023-11-21 19:25:50 +04:00
committed by GitHub
parent 5a08a26c9a
commit a8576c2340
3 changed files with 54 additions and 6 deletions
+40
View File
@@ -9,6 +9,7 @@ import Control.Concurrent (threadDelay)
import Control.Concurrent.Async (concurrently_)
import Control.Monad (when, void)
import qualified Data.ByteString as B
import Data.List (isInfixOf)
import qualified Data.Text as T
import Simplex.Chat.Controller (ChatConfig (..), XFTPFileConfig (..))
import Simplex.Chat.Protocol (supportedChatVRange)
@@ -107,6 +108,7 @@ chatGroupTests = do
it "sends and updates profile when creating contact" testMemberContactProfileUpdate
describe "group message forwarding" $ do
it "forward messages between invitee and introduced (x.msg.new)" testGroupMsgForward
it "deduplicate forwarded messages" testGroupMsgForwardDeduplicate
it "forward message edit (x.msg.update)" testGroupMsgForwardEdit
it "forward message reaction (x.msg.react)" testGroupMsgForwardReaction
it "forward message deletion (x.msg.del)" testGroupMsgForwardDeletion
@@ -3947,6 +3949,44 @@ setupGroupForwarding3 gName alice bob cath = do
void $ withCCTransaction alice $ \db ->
DB.execute_ db "UPDATE group_member_intros SET intro_status='fwd'"
testGroupMsgForwardDeduplicate :: HasCallStack => FilePath -> IO ()
testGroupMsgForwardDeduplicate =
testChat3 aliceProfile bobProfile cathProfile $
\alice bob cath -> do
createGroup3 "team" alice bob cath
threadDelay 1000000 -- delay so intro_status doesn't get overwritten to connected
void $ withCCTransaction alice $ \db ->
DB.execute_ db "UPDATE group_member_intros SET intro_status='fwd'"
bob #> "#team hi there"
alice <# "#team bob> hi there"
cath
<### [ Predicate ("#team bob> hi there" `isInfixOf`),
StartsWith "duplicate group message, group id: 1"
]
threadDelay 1000000
-- cath sends x.grp.mem.con on deduplication, so alice doesn't forward anymore
cath #> "#team hey team"
alice <# "#team cath> hey team"
bob <# "#team cath> hey team"
alice ##> "/tail #team 2"
alice <# "#team bob> hi there"
alice <# "#team cath> hey team"
bob ##> "/tail #team 2"
bob <# "#team hi there"
bob <# "#team cath> hey team"
cath ##> "/tail #team 2"
cath <#. "#team bob> hi there"
cath <# "#team hey team"
testGroupMsgForwardEdit :: HasCallStack => FilePath -> IO ()
testGroupMsgForwardEdit =
testChat3 aliceProfile bobProfile cathProfile $
+7 -2
View File
@@ -282,8 +282,12 @@ cc <##.. ls = do
unless prefix $ print ("expected to start from one of: " <> show ls, ", got: " <> l)
prefix `shouldBe` True
data ConsoleResponse = ConsoleString String | WithTime String | EndsWith String | StartsWith String
deriving (Show)
data ConsoleResponse
= ConsoleString String
| WithTime String
| EndsWith String
| StartsWith String
| Predicate (String -> Bool)
instance IsString ConsoleResponse where fromString = ConsoleString
@@ -303,6 +307,7 @@ getInAnyOrder f cc ls = do
WithTime s -> dropTime_ l == Just s
EndsWith s -> s `isSuffixOf` l
StartsWith s -> s `isPrefixOf` l
Predicate p -> p l
filterFirst :: (a -> Bool) -> [a] -> [a]
filterFirst _ [] = []
filterFirst p (x:xs)