From cc2c1e0dae1302ef34deb4d311c66e39c17578ab Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 8 Jan 2024 18:52:55 +0000 Subject: [PATCH] delays --- src/Simplex/Messaging/Crypto.hs | 2 +- src/Simplex/Messaging/Encoding.hs | 4 ++-- tests/AgentTests/NotificationTests.hs | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Simplex/Messaging/Crypto.hs b/src/Simplex/Messaging/Crypto.hs index 506e8e7cd..174956751 100644 --- a/src/Simplex/Messaging/Crypto.hs +++ b/src/Simplex/Messaging/Crypto.hs @@ -924,7 +924,7 @@ pad msg paddedLen pad' :: Builder -> Int -> Either CryptoError Builder pad' msg paddedLen - | len <= maxMsgLen && padLen >= 0 = Right $ word16BE (fromIntegral len) <> msg <> byteString (B.replicate padLen '#') + | len <= maxMsgLen && padLen >= 0 = Right $ byteString (encodeWord16 $ fromIntegral len) <> msg <> byteString (B.replicate padLen '#') | otherwise = Left CryptoLargeMsgError where len = fromIntegral $ LB.length $ toLazyByteString msg diff --git a/src/Simplex/Messaging/Encoding.hs b/src/Simplex/Messaging/Encoding.hs index 434269ed4..ac9c8b7d8 100644 --- a/src/Simplex/Messaging/Encoding.hs +++ b/src/Simplex/Messaging/Encoding.hs @@ -22,7 +22,7 @@ where import Data.Attoparsec.ByteString.Char8 (Parser) import qualified Data.Attoparsec.ByteString.Char8 as A import Data.Bits (shiftL, shiftR, (.|.)) -import Data.ByteString.Builder (Builder, lazyByteString, word16BE) +import Data.ByteString.Builder (Builder, byteString, lazyByteString, word16BE) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Lazy.Char8 as LB @@ -142,7 +142,7 @@ instance Encoding Large where {-# INLINE smpP #-} encodeLarge :: LB.ByteString -> Builder -encodeLarge s = word16BE (fromIntegral $ LB.length s) <> lazyByteString s +encodeLarge s = byteString (encodeWord16 $ fromIntegral $ LB.length s) <> lazyByteString s {-# INLINE encodeLarge #-} instance Encoding SystemTime where diff --git a/tests/AgentTests/NotificationTests.hs b/tests/AgentTests/NotificationTests.hs index 053c6200c..6338b8d0a 100644 --- a/tests/AgentTests/NotificationTests.hs +++ b/tests/AgentTests/NotificationTests.hs @@ -503,13 +503,14 @@ testNotificationsSMPRestartBatch :: Int -> ATransport -> APNSMockServer -> IO () testNotificationsSMPRestartBatch n t APNSMockServer {apnsQ} = do a <- getSMPAgentClient' agentCfg initAgentServers2 testDB b <- getSMPAgentClient' agentCfg initAgentServers2 testDB2 + threadDelay 3000000 conns <- runServers $ do liftIO $ print 1 conns <- replicateM (n :: Int) $ makeConnection a b liftIO $ print 2 _ <- registerTestToken a "abcd" NMInstant apnsQ liftIO $ print 3 - liftIO $ threadDelay 1500000 + liftIO $ threadDelay 3000000 liftIO $ print 4 forM_ (zip [0..] conns) $ \(i, (aliceId, bobId)) -> do liftIO $ putStrLn $ "*** msg " <> show i