diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 33309c0ea..c835a6829 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -79,7 +79,7 @@ jobs:
# =============================
build:
- name: "ubuntu-${{ matrix.os }}-${{ matrix.arch }}, GHC: ${{ matrix.ghc }}"
+ name: "ubuntu-${{ matrix.os }}-${{ matrix.arch }}, GHC: ${{ matrix.ghc }}${{ matrix.client_postgres && ', PostgreSQL agent store' || '' }}"
needs: maybe-release
if: needs.maybe-release.outputs.reduced != 'true'
permissions:
@@ -126,6 +126,12 @@ jobs:
runner: "ubuntu-22.04"
ghc: "9.6.3"
should_run: true
+ - os: 24.04
+ os_underscore: 24_04
+ arch: x86-64
+ runner: "ubuntu-24.04"
+ ghc: "9.6.3"
+ should_run: true
- os: 24.04
os_underscore: 24_04
arch: x86-64
@@ -223,7 +229,7 @@ jobs:
toolchain=$(docker exec builder dpkg-query -W -f '${db:Status-Status} ${binary:Package} ${Version}\n' 'binutils*' 'cpp*' 'gcc*' '*-dev' | grep '^installed ' | sha256sum | cut -c1-16)
target=${{ matrix.os }}-${{ matrix.arch }}-ghc${{ matrix.ghc }}-$toolchain
echo "deps=deps-$target" >> "$GITHUB_OUTPUT"
- echo "dist=dist-$target" >> "$GITHUB_OUTPUT"
+ echo "dist=dist-$target${{ matrix.client_postgres && '-client-postgres' || '' }}" >> "$GITHUB_OUTPUT"
- name: Restore dependencies from cache
id: restore-deps
@@ -264,7 +270,7 @@ jobs:
- name: Build smp-server, xftp-server (postgresql) and tests
id: build-postgres
- if: matrix.should_run == true
+ if: matrix.should_run == true && matrix.client_postgres != true
shell: docker exec -t builder sh -eu {0}
run: |
chmod -fR 777 ~/.cabal ./dist-newstyle ./dist-postgres ./dist-client-postgres || :; git config --global --add safe.directory '*'
@@ -280,7 +286,7 @@ jobs:
strip /out/smp-server /out/xftp-server /out/ntf-server
- name: Copy simplexmq-test from container
- if: matrix.should_run == true
+ if: matrix.should_run == true && matrix.client_postgres != true
shell: bash
run: |
docker cp builder:/out/simplexmq-test .
@@ -290,7 +296,11 @@ jobs:
if: matrix.should_run == true && matrix.client_postgres == true
shell: docker exec -t builder sh -eu {0}
run: |
+ chmod -fR 777 ~/.cabal ./dist-client-postgres || :; git config --global --add safe.directory '*'
+ scripts/ci/prune-old-builds.sh dist-client-postgres
+ cabal update
cabal build --builddir=dist-client-postgres --jobs=$(nproc) --enable-tests -fserver_postgres -fclient_postgres -fslow_servers ${{ env.ghc_options }} simplexmq-test
+ mkdir -p /out
bin=$(find /project/dist-client-postgres -name simplexmq-test -type f -executable)
cp "$bin" /out/simplexmq-test-client-postgres
@@ -301,7 +311,7 @@ jobs:
docker cp builder:/out/simplexmq-test-client-postgres .
- name: Copy smp-server, xftp-server (postgresql) from container and prepare it
- if: startsWith(github.ref, 'refs/tags/v') && matrix.should_run == true
+ if: startsWith(github.ref, 'refs/tags/v') && matrix.should_run == true && matrix.client_postgres != true
id: prepare-postgres
shell: bash
run: |
@@ -326,7 +336,7 @@ jobs:
- name: Build everything else (standard)
id: build-standard
- if: matrix.should_run == true && needs.maybe-release.outputs.reduced != 'true'
+ if: matrix.should_run == true && matrix.client_postgres != true && needs.maybe-release.outputs.reduced != 'true'
shell: docker exec -t builder sh -eu {0}
run: |
cabal build --jobs=$(nproc) ${{ env.ghc_options }}
@@ -340,7 +350,7 @@ jobs:
- name: Copy binaries from container and prepare them
id: prepare-regular
- if: startsWith(github.ref, 'refs/tags/v') && matrix.should_run == true
+ if: startsWith(github.ref, 'refs/tags/v') && matrix.should_run == true && matrix.client_postgres != true
shell: bash
run: |
docker cp builder:/out .
@@ -365,7 +375,7 @@ jobs:
cat hashes.output >> "$GITHUB_OUTPUT"
- name: Upload binaries
- if: startsWith(github.ref, 'refs/tags/v') && matrix.should_run == true
+ if: startsWith(github.ref, 'refs/tags/v') && matrix.should_run == true && matrix.client_postgres != true
uses: simplex-chat/action-gh-release@v2
with:
append_body: true
@@ -439,7 +449,7 @@ jobs:
npm run build
- name: Test
- if: matrix.should_run == true && matrix.arch == 'x86-64'
+ if: matrix.should_run == true && matrix.arch == 'x86-64' && matrix.client_postgres != true
timeout-minutes: 120
shell: bash
env: &test-env
@@ -464,7 +474,7 @@ jobs:
- name: Remove -O2 build directories
id: remove-o2
- if: env.cache_o0 == 'true' && !cancelled() && steps.build-postgres.outcome == 'success' && steps.build-standard.outcome != 'failure'
+ if: env.cache_o0 == 'true' && !cancelled() && (steps.build-postgres.outcome == 'success' || steps.build-client-postgres.outcome == 'success') && steps.build-standard.outcome != 'failure'
shell: docker exec -t builder sh -eu {0}
run: rm -rf dist-newstyle dist-postgres dist-client-postgres
@@ -492,10 +502,11 @@ jobs:
shell: docker exec -t builder sh -eu {0}
run: |
scripts/ci/prune-old-builds.sh dist-newstyle dist-postgres dist-client-postgres
- cabal build --builddir=dist-postgres --jobs=$(nproc) --enable-tests -fserver_postgres --ghc-options=-O0
- cabal build --jobs=$(nproc) --ghc-options=-O0
if [ "${{ matrix.client_postgres }}" = true ]; then
cabal build --builddir=dist-client-postgres --jobs=$(nproc) --enable-tests -fserver_postgres -fclient_postgres -fslow_servers --ghc-options=-O0 simplexmq-test
+ else
+ cabal build --builddir=dist-postgres --jobs=$(nproc) --enable-tests -fserver_postgres --ghc-options=-O0
+ cabal build --jobs=$(nproc) --ghc-options=-O0
fi
- name: Record source hashes for -O0 build (GHC 8.10.7)
@@ -514,7 +525,7 @@ jobs:
key: ${{ steps.keys.outputs.dist }}-O0-${{ env.branch }}-${{ github.sha }}
build-reduced:
- name: "ubuntu-${{ matrix.os }}-${{ matrix.arch }}, GHC: ${{ matrix.ghc }}"
+ name: "ubuntu-${{ matrix.os }}-${{ matrix.arch }}, GHC: ${{ matrix.ghc }}${{ matrix.client_postgres && ', PostgreSQL agent store' || '' }}"
needs: maybe-release
if: needs.maybe-release.outputs.reduced == 'true'
permissions:
@@ -524,8 +535,15 @@ jobs:
runs-on: ${{ matrix.runner }}
services: *build-services
strategy:
+ fail-fast: false
matrix:
include:
+ - os: 24.04
+ os_underscore: 24_04
+ arch: x86-64
+ runner: "ubuntu-24.04"
+ ghc: "9.6.3"
+ should_run: true
- os: 24.04
os_underscore: 24_04
arch: x86-64
diff --git a/scripts/ci/README.md b/scripts/ci/README.md
index dd57e687d..1c9a1a30a 100644
--- a/scripts/ci/README.md
+++ b/scripts/ci/README.md
@@ -6,10 +6,10 @@
| Trigger | Build | Jobs |
|---|---|---|
-| a push to a draft pull request
a manual run (workflow_dispatch)
a push to master or stable in a fork | reduced | build-reduced: ubuntu-24.04 x86-64, GHC 9.6.3, at -O0 (-O2 on pushes), without the standard build |
-| a pull request marked ready for review, and later pushes to it
a push to master or stable in simplex-chat/simplexmq
a push of a v* tag | full | build: 5 entries (GHC 8.10.7 and 9.6.3, x86-64 and aarch64), at -O0 on pull requests and -O2 on pushes |
+| a push to a draft pull request
a manual run (workflow_dispatch)
a push to master or stable in a fork | reduced | build-reduced: 2 entries, ubuntu-24.04 x86-64, GHC 9.6.3, at -O0 (-O2 on pushes), without the standard build |
+| a pull request marked ready for review, and later pushes to it
a push to master or stable in simplex-chat/simplexmq
a push of a v* tag | full | build: 6 entries (GHC 8.10.7 and 9.6.3, x86-64 and aarch64), at -O0 on pull requests and -O2 on pushes |
-Both builds also run maybe-release and resolver (python). Tests run on the x86-64 entries, after xftp-web is built with Node.js 22 (`npm install`, `npm run build`) for the XFTP Web Client tests. The ubuntu-24.04 x86-64 entry also runs the tests built with `-fclient_postgres -fslow_servers` (agent with the PostgreSQL store, and XFTP servers that delay responses for the slow-server test, which the other builds skip), in the build directory dist-client-postgres, in step "Test with PostgreSQL agent store". After the tests, step "Check generated files" fails if a test changed a tracked file: the schema dump and query plan tests overwrite their files, so a stale file fails here even when the test passes on retry. The reduced build restores the -O0 build caches saved by master pushes; the Docker image cache is tagged by ISO week, so the first run of a week rebuilds the image.
+Both builds also run maybe-release and resolver (python). Tests run on the x86-64 entries, after xftp-web is built with Node.js 22 (`npm install`, `npm run build`) for the XFTP Web Client tests. In both builds, the ubuntu-24.04 x86-64 entry named "PostgreSQL agent store" builds and runs only the tests built with `-fclient_postgres -fslow_servers` (agent with the PostgreSQL store, and XFTP servers that delay responses for the slow-server test, which the other builds skip), in the build directory dist-client-postgres, in step "Test with PostgreSQL agent store", in parallel with the other entries; its build directory has its own cache key. After the tests, step "Check generated files" fails if a test changed a tracked file: the schema dump and query plan tests overwrite their files, so a stale file fails here even when the test passes on retry. The reduced build restores the -O0 build caches saved by master pushes; the Docker image cache is tagged by ISO week, so the first run of a week rebuilds the image.
## Test selection
diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs
index 65a6d05b0..a17f79019 100644
--- a/src/Simplex/Messaging/Agent.hs
+++ b/src/Simplex/Messaging/Agent.hs
@@ -1009,12 +1009,18 @@ ackMessageAsync' c corrId connId msgId rcptInfo_ = do
SCNew -> throwE $ CMD PROHIBITED "ackMessageAsync: SCNew"
where
enqueueAck :: AM ()
- enqueueAck = do
+ enqueueAck =
+ withStore' c storeUserAck >>= \case
+ Right server -> lift . void $ getAsyncCmdWorker True c connId (Just server)
+ Left (SEMsgNotFound _) -> pure ()
+ Left e -> throwE $ storeError e
+ storeUserAck :: DB.Connection -> IO (Either StoreError SMPServer)
+ storeUserAck db = runExceptT $ do
let mId = InternalId msgId
- RcvMsg {msgType} <- withStore c $ \db -> getRcvMsg db connId mId
- when (isJust rcptInfo_ && msgType /= AM_A_MSG_) $ throwE $ CMD PROHIBITED "ackMessageAsync: receipt not allowed"
- (RcvQueue {server}, _) <- withStore c $ \db -> setMsgUserAck db connId mId
- enqueueCommand c corrId connId (Just server) . AClientCommand $ ACK msgId rcptInfo_
+ RcvMsg {msgType} <- ExceptT $ getRcvMsg db connId mId
+ when (isJust rcptInfo_ && msgType /= AM_A_MSG_) $ throwE $ SEAgentError $ CMD PROHIBITED "ackMessageAsync: receipt not allowed"
+ (RcvQueue {server}, _) <- ExceptT $ setMsgUserAck db connId mId
+ server <$ ExceptT (createCommand db corrId connId (Just server) . AClientCommand $ ACK msgId rcptInfo_)
deleteConnectionAsync' :: AgentClient -> Bool -> ConnId -> AM ()
deleteConnectionAsync' c waitDelivery connId = deleteConnectionsAsync' c waitDelivery [connId]
@@ -2841,24 +2847,22 @@ ackMessage' :: AgentClient -> Maybe AsyncCmdId -> ConnId -> AgentMsgId -> Maybe
ackMessage' c cmdId_ connId msgId rcptInfo_ = withConnLockNotify c connId "ackMessage" $ do
SomeConn _ conn <- withStore c (`getConn` connId)
case conn of
- DuplexConnection {} -> do
- t_ <- ack
- sendRcpt conn
- del
- pure t_
- RcvConnection {} -> do
- t_ <- ack
- del
- pure t_
+ DuplexConnection {} -> ack $ sendRcpt conn
+ RcvConnection {} -> ack $ pure ()
SndConnection {} -> throwE $ CONN SIMPLEX "ackMessage"
ContactConnection {} -> throwE $ CMD PROHIBITED "ackMessage: ContactConnection"
NewConnection _ -> throwE $ CMD PROHIBITED "ackMessage: NewConnection"
where
- ack :: AM (Maybe ATransmission)
- ack = do
+ ack :: AM () -> AM (Maybe ATransmission)
+ ack afterAck =
-- the stored message was delivered via a specific queue, the rest failed to decrypt and were already acknowledged
- (rq, srvMsgId) <- withStore c $ \db -> setMsgUserAck db connId $ InternalId msgId
- ackQueueMessage c rq srvMsgId
+ withStore' c (\db -> setMsgUserAck db connId $ InternalId msgId) >>= \case
+ Right (rq, srvMsgId) -> do
+ t_ <- ackQueueMessage c rq srvMsgId
+ afterAck
+ t_ <$ del
+ Left (SEMsgNotFound _) -> Nothing <$ del
+ Left e -> throwE $ storeError e
del :: AM ()
del = withStore' c $ \db -> deleteMsg db connId (InternalId msgId) >> mapM_ (deleteCommand db) cmdId_
sendRcpt :: Connection 'CDuplex -> AM ()
@@ -3797,9 +3801,10 @@ processSMPTransmissions c@AgentClient {subQ, smpServersStats} (tSess@(userId, sr
liftEither (parse smpP (AGENT $ A_MESSAGE "parse msg body 1") agentMsgBody) >>= \case
AgentMessage _ (A_MSG body) -> do
logServer "<--" c srv rId $ "MSG :" <> logSecret' (SMP.unMsgId srvMsgId)
- notify $ MSG msgMeta msgFlags body
+ notify $ MSG msgMeta {redelivered = True} msgFlags body
pure ACKPending
- _ -> ack
+ AgentMessage _ (A_RCVD rcpts) -> qDuplex conn' "RCVD" $ messagesRcvd rcpts msgMeta {redelivered = True}
+ _ -> ackDel internalId
_ -> checkDuplicateHash e encryptedMsgHash >> ack
Left (AGENT (A_CRYPTO e)) -> do
incSMPServerStat c userId srv recvCryptoErrs
@@ -3838,7 +3843,7 @@ processSMPTransmissions c@AgentClient {subQ, smpServersStats} (tSess@(userId, sr
let integrity = checkMsgIntegrity prevExtSndId sndMsgId prevRcvMsgHash prevMsgHash
recipient = (unId internalId, internalTs)
broker = (srvMsgId, systemToUTCTime srvTs)
- msgMeta = MsgMeta {integrity, recipient, broker, sndMsgId, pqEncryption}
+ msgMeta = MsgMeta {integrity, recipient, broker, sndMsgId, pqEncryption, redelivered = False}
rcvMsg = RcvMsgData {msgMeta, msgType, msgFlags, msgBody = agentMsgBody, internalRcvId, internalHash, externalPrevSndHash = prevMsgHash, encryptedMsgHash}
liftIO $ createRcvMsg db connId rq rcvMsg
pure $ Just (internalId, msgMeta, aMessage, rc)
@@ -4087,28 +4092,30 @@ processSMPTransmissions c@AgentClient {subQ, smpServersStats} (tSess@(userId, sr
Nothing -> qError "QCONT: queue address not found"
messagesRcvd :: NonEmpty AMessageReceipt -> MsgMeta -> Connection 'CDuplex -> AM ACKd
- messagesRcvd rcpts msgMeta@MsgMeta {broker = (srvMsgId, _)} _ = do
+ messagesRcvd rcpts msgMeta@MsgMeta {recipient = (rcptMsgId, _), broker = (srvMsgId, _)} _ = do
logServer "<--" c srv rId $ "MSG :" <> logSecret' (SMP.unMsgId srvMsgId)
rs <- forM rcpts $ \rcpt -> clientReceipt rcpt `catchAllErrors` \e -> notify (ERR e) $> Nothing
case L.nonEmpty . catMaybes $ L.toList rs of
Just rs' -> notify (RCVD msgMeta rs') $> ACKPending
- Nothing -> notifyIntegrity msgMeta >> ack
+ Nothing -> notifyIntegrity msgMeta >> ackDel
where
- ack :: AM ACKd
- ack = enqueueCmd (ICAck rId srvMsgId) $> ACKd
+ ackDel :: AM ACKd
+ ackDel = enqueueCmd (ICAckDel rId srvMsgId $ InternalId rcptMsgId) $> ACKd
clientReceipt :: AMessageReceipt -> AM (Maybe MsgReceipt)
clientReceipt AMessageReceipt {agentMsgId, msgHash} = do
let sndMsgId = InternalSndId agentMsgId
- SndMsg {internalId = InternalId msgId, msgType, internalHash, msgReceipt} <- withStore c $ \db -> getSndMsgViaRcpt db connId sndMsgId
- if msgType /= AM_A_MSG_
- then prohibited "receipt: not a msg" $> Nothing
- else case msgReceipt of
- Just MsgReceipt {msgRcptStatus = MROk} -> pure Nothing -- already notified with MROk status
- _ -> do
- let msgRcptStatus = if msgHash == internalHash then MROk else MRBadMsgHash
- rcpt = MsgReceipt {agentMsgId = msgId, msgRcptStatus}
- withStore' c $ \db -> updateSndMsgRcpt db connId sndMsgId rcpt
- pure $ Just rcpt
+ withStore' c (\db -> getSndMsgViaRcpt db connId sndMsgId) >>= \case
+ Right SndMsg {internalId = InternalId msgId, msgType, internalHash, msgReceipt}
+ | msgType /= AM_A_MSG_ -> prohibited "receipt: not a msg" $> Nothing
+ | otherwise -> case msgReceipt of
+ Just MsgReceipt {agentMsgId = rcptId, msgRcptStatus = MROk} | rcptId /= rcptMsgId -> pure Nothing -- already notified with MROk status
+ _ -> do
+ let msgRcptStatus = if msgHash == internalHash then MROk else MRBadMsgHash
+ rcpt = MsgReceipt {agentMsgId = msgId, msgRcptStatus}
+ withStore' c $ \db -> updateSndMsgRcpt db connId sndMsgId MsgReceipt {agentMsgId = rcptMsgId, msgRcptStatus}
+ pure $ Just rcpt
+ Left (SEMsgNotFound _) -> pure Nothing
+ Left e -> throwE $ storeError e
-- processed by queue sender
qAddMsg :: SMP.MsgId -> NonEmpty (SMPQueueUri, Maybe SndQAddr) -> Connection 'CDuplex -> AM ()
diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs
index 35ae55b5e..1d28db006 100644
--- a/src/Simplex/Messaging/Agent/Protocol.hs
+++ b/src/Simplex/Messaging/Agent/Protocol.hs
@@ -839,7 +839,8 @@ data MsgMeta = MsgMeta
recipient :: (AgentMsgId, UTCTime),
broker :: (MsgId, UTCTime),
sndMsgId :: AgentMsgId,
- pqEncryption :: PQEncryption
+ pqEncryption :: PQEncryption,
+ redelivered :: Bool
}
deriving (Eq, Show)
diff --git a/src/Simplex/Messaging/Agent/Store/AgentStore.hs b/src/Simplex/Messaging/Agent/Store/AgentStore.hs
index f77434bf6..41685f2e2 100644
--- a/src/Simplex/Messaging/Agent/Store/AgentStore.hs
+++ b/src/Simplex/Messaging/Agent/Store/AgentStore.hs
@@ -1263,7 +1263,7 @@ getLastMsg db connId msgId =
m.msg_type, m.msg_body, m.pq_encryption, s.internal_id, s.rcpt_status, r.user_ack
FROM rcv_messages r
JOIN messages m ON r.conn_id = m.conn_id AND r.internal_id = m.internal_id
- JOIN connections c ON r.conn_id = c.conn_id AND c.last_internal_msg_id = r.internal_id
+ JOIN connections c ON r.conn_id = c.conn_id AND c.last_internal_rcv_msg_id = r.internal_rcv_id
LEFT JOIN snd_messages s ON s.conn_id = r.conn_id AND s.rcpt_internal_id = r.internal_id
WHERE r.conn_id = ? AND r.broker_id = ?
|]
@@ -1271,7 +1271,7 @@ getLastMsg db connId msgId =
toRcvMsg :: (Int64, InternalTs, BrokerId, BrokerTs) :. (AgentMsgId, MsgIntegrity, MsgHash, AgentMessageType, MsgBody, PQEncryption, Maybe AgentMsgId, Maybe MsgReceiptStatus, BoolInt) -> RcvMsg
toRcvMsg ((agentMsgId, internalTs, brokerId, brokerTs) :. (sndMsgId, integrity, internalHash, msgType, msgBody, pqEncryption, rcptInternalId_, rcptStatus_, BI userAck)) =
- let msgMeta = MsgMeta {recipient = (agentMsgId, internalTs), broker = (brokerId, brokerTs), sndMsgId, integrity, pqEncryption}
+ let msgMeta = MsgMeta {recipient = (agentMsgId, internalTs), broker = (brokerId, brokerTs), sndMsgId, integrity, pqEncryption, redelivered = False}
msgReceipt = MsgReceipt <$> rcptInternalId_ <*> rcptStatus_
in RcvMsg {internalId = InternalId agentMsgId, msgMeta, msgType, msgBody, internalHash, msgReceipt, userAck}
diff --git a/src/Simplex/Messaging/Transport/Client.hs b/src/Simplex/Messaging/Transport/Client.hs
index 1fd81e5b1..24dcc4483 100644
--- a/src/Simplex/Messaging/Transport/Client.hs
+++ b/src/Simplex/Messaging/Transport/Client.hs
@@ -60,7 +60,7 @@ import Simplex.Messaging.Parsers (parseAll, parseString)
import Simplex.Messaging.Transport
import Simplex.Messaging.Transport.KeepAlive
import Simplex.Messaging.Transport.Shared
-import Simplex.Messaging.Util (bshow, catchAll, catchAll_, tshow, (<$?>))
+import Simplex.Messaging.Util (bshow, catchAll_, catchOwn, tshow, (<$?>))
import System.IO.Error
import Text.Read (readMaybe)
import UnliftIO.Exception (IOException)
@@ -175,7 +175,7 @@ runTLSTransportClient tlsParams caStore_ cfg@TransportClientConfig {socksProxy,
h <- newIORef Nothing
let set hc = (>>= \c -> writeIORef h (Just $ hc c) $> c)
E.bracket (set CHSocket $ connectTCP port) (\_ -> closeConn h) $ \sock -> do
- mapM_ (setSocketKeepAlive sock) tcpKeepAlive `catchAll` \e -> logError ("Error setting TCP keep-alive " <> tshow e)
+ mapM_ (setSocketKeepAlive sock) tcpKeepAlive `catchOwn` \e -> logError ("Error setting TCP keep-alive " <> tshow e)
let tCfg = clientTransportConfig cfg
-- No TLS timeout to avoid failing connections via SOCKS
tls <- set CHContext $ connectTLS (Just hostName) tCfg clientParams sock
diff --git a/tests/AgentTests/FunctionalAPITests.hs b/tests/AgentTests/FunctionalAPITests.hs
index 18ee7dd8a..6c201c35d 100644
--- a/tests/AgentTests/FunctionalAPITests.hs
+++ b/tests/AgentTests/FunctionalAPITests.hs
@@ -45,6 +45,7 @@ module AgentTests.FunctionalAPITests
nGet,
pGet,
getInAnyOrder,
+ withUP,
(##>),
(=##>),
pattern CON,
@@ -100,7 +101,7 @@ import Simplex.Messaging.Agent.Env.SQLite (AgentConfig (..), Env (..), InitialAg
import Simplex.Messaging.Agent.Protocol hiding (CON, CONF, INFO, REQ, SENT)
import qualified Simplex.Messaging.Agent.Protocol as A
import Simplex.Messaging.Agent.Store (Connection' (..), SomeConn' (..), StoredRcvQueue (..), StoredSndQueue (..))
-import Simplex.Messaging.Agent.Store.AgentStore (deleteRatchetKeyHashesExpired, getConn, getConnIds, getRatchetX3dhKeys)
+import Simplex.Messaging.Agent.Store.AgentStore (deleteRatchetKeyHashesExpired, deleteSndMsgsExpired, getConn, getConnIds, getRatchetX3dhKeys)
import Simplex.Messaging.Agent.Store.Common (DBStore (..), withTransaction)
import Simplex.Messaging.Agent.Store.Interface
import qualified Simplex.Messaging.Agent.Store.DB as DB
@@ -210,6 +211,13 @@ pGet' c skipWarn = do
SFWARN {} | skipWarn -> pGet c
_ -> pure t
+waitDisconnected :: HasCallStack => AgentClient -> IO ()
+waitDisconnected c =
+ timeout 5000000 (atomically $ readTBQueue $ subQ c) >>= \case
+ Just (_, _, AEvt SAENone (CONNECT _ _)) -> waitDisconnected c
+ Just (_, _, AEvt SAENone (DISCONNECT _ _)) -> pure ()
+ r -> error $ "expected DISCONNECT, received " <> show r
+
pattern CONF :: ConfirmationId -> [SMPServer] -> ConnInfo -> AEvent e
pattern CONF conId srvs connInfo <- A.CONF conId PQSupportOn srvs connInfo
@@ -470,6 +478,10 @@ functionalAPITests ps = do
testDeliverClientRestart ps
it "should deliver messages to the user once, even if repeat delivery is made by the server (no ACK)" $
testDuplicateMessage ps
+ it "should deliver message again after client restart when a message was sent after it" $
+ testDuplicateMessageAfterSent ps
+ it "should acknowledge a message again after it is deleted" $
+ withSmpServer ps testAckDeletedMessage
it "should report error via msg integrity on skipped messages" $
testSkippedMessages ps
it "should connect to the server when server goes up if it initially was down" $
@@ -646,6 +658,11 @@ functionalAPITests ps = do
withSmpServer ps testConnectionVerifyCodes
describe "Delivery receipts" $ do
it "should send and receive delivery receipt" $ withSmpServer ps testDeliveryReceipts
+ it "should deliver receipt again after client restart without acknowledgement" $ testDuplicateReceipt ps False False
+ it "should deliver receipt again after client restart before its status is saved" $ testDuplicateReceipt ps True False
+ it "should deliver receipt again after client restart when a message was sent after it" $ testDuplicateReceipt ps False True
+ it "should delete sent message after its receipt is acknowledged" $ withSmpServer ps testReceiptDeletesSentMessage
+ it "should accept and delete receipt for deleted sent message" $ withSmpServer ps testReceiptForDeletedSentMessage
it "send delivery receipts concurrently with messages" $ testDeliveryReceiptsConcurrent ps
describe "Connections with apps of earlier versions" $ do
describe "app with agent versions 2-6, client versions 1-3, e2e versions 2-3" $
@@ -1623,18 +1640,24 @@ testServiceRequestResilient ps = withAgentClients2 $ \service client -> do
reqAsync <- async $ runExceptT $ sendServiceRequestAsync client 1 connReq Nothing Nothing "resilient request"
threadDelay 500000 -- let the enqueued send retry against the down server before bringing it up
-- server up: the request is delivered and the service receives it
- invId <- withSmpServerStoreLogOn ps testPort $ \_ -> runRight $ do
- ("", "", UP _ _) <- nGet service
- ("", _, SREQ invId _ "resilient request") <- get service
- pure invId :: ExceptT AgentErrorType IO InvitationId
+ invId <- withSmpServerStoreLogOn ps testPort $ \_ -> do
+ let upOrReq =
+ pGet service >>= \case
+ ("", "", AEvt SAENone (UP _ _)) -> pure $ Left ()
+ ("", _, AEvt SAEConn (SREQ i _ "resilient request")) -> pure $ Right i
+ r -> error $ "unexpected event: " <> show r
+ ([()], [i]) <- partitionEithers <$> replicateM 2 upOrReq
+ pure i
("", "", DOWN _ _) <- nGet service
-- server down: the service replies; the async reply is enqueued and retried until the server is back
replyConnId <- runRight $ sendServiceReplyAsync service "1" 1 invId "resilient response"
-- server up: the reply is delivered, the requester's blocking call returns the response, the service gets SENT
resp <- withSmpServerStoreLogOn ps testPort $ \_ -> do
- ("", "", UP _ _) <- nGet service
- ("", sentConnId, A.SSENT _ _) <- get service
- sentConnId `shouldBe` replyConnId
+ getInAnyOrder
+ service
+ [ \case ("", "", AEvt SAENone (UP _ _)) -> True; _ -> False,
+ \case ("", c, AEvt SAEConn (A.SSENT _ _)) -> c == replyConnId; _ -> False
+ ]
wait reqAsync
resp `shouldBe` Right "resilient response"
@@ -1789,10 +1812,8 @@ testAllowConnectionClientRestart ps@(t, ASType qsType _) = do
threadDelay 500000
withSmpServerConfigOn t (cfgS2QS qsType) testPort2 $ \_ -> do
runRight $ do
- ("", "", UP _ _) <- nGet bob
+ liftIO $ getUpInfoCon bob [aliceId] aliceId "alice's connInfo"
get alice2 ##> ("", bobId, CON)
- get bob ##> ("", aliceId, INFO "alice's connInfo")
- get bob ##> ("", aliceId, CON)
exchangeGreetings alice2 bobId bob aliceId
disposeAgentClient alice2
disposeAgentClient bob
@@ -1841,9 +1862,7 @@ testInvitationErrors ps restart = do
("", "", DOWN _ [_]) <- nGet a
withServer2 ps $ do
get a ##> ("", bId, CON) -- note that server 1 is down, CON event is sent when HELLO is sent to server 2
- ("", "", UP _ [_]) <- nGet b'
- get b' ##> ("", aId, INFO "alice's connInfo")
- get b' ##> ("", aId, CON)
+ getUpInfoCon b' [aId] aId "alice's connInfo"
withServer1 ps $ do
("", "", UP _ [_]) <- nGet a
runRight_ $ exchangeGreetingsViaProxyMsgId_ False PQEncOn 2 (2 + n) a bId b' aId
@@ -1867,6 +1886,20 @@ restartAgent_ getAgent restart c cIds
pure c'
| otherwise = pure c
+getUpInfoCon :: HasCallStack => AgentClient -> [ConnId] -> ConnId -> ConnInfo -> Expectation
+getUpInfoCon c upConnIds connId info =
+ getInAnyOrder
+ c
+ [ \case ("", "", AEvt SAENone (UP _ cs)) -> S.fromList cs == S.fromList upConnIds; _ -> False,
+ \case ("", cId, AEvt SAEConn (INFO info')) -> cId == connId && info' == info; _ -> False,
+ \case ("", cId, AEvt SAEConn CON) -> cId == connId; _ -> False
+ ]
+
+waitAck :: AgentClient -> ConnId -> IO ()
+waitAck c connId = do
+ ServerQueueInfo {info = QueueInfo {qiSize}} <- runRight $ getConnectionQueueInfo c NRMInteractive connId
+ when (qiSize > 0) $ threadDelay 20000 >> waitAck c connId
+
testContactErrors :: (HasCallStack, HasTestEnv) => (ASrvTransport, AStoreType) -> Bool -> IO ()
testContactErrors ps restart = do
a <- getAgentA
@@ -1896,6 +1929,7 @@ testContactErrors ps restart = do
Left _ -> putStrLn "retrying send" >> threadDelay 200000 >> loopSend
loopSend
("", _, A.REQ invId PQSupportOn _ "bob's connInfo" _ _) <- get a
+ waitAck a contactId
pure invId
("", "", DOWN _ [_]) <- nGet a
(bId, _) <- runRight $ A.prepareConnectionToAccept a 1 True invId PQSupportOn
@@ -1925,17 +1959,12 @@ testContactErrors ps restart = do
Left _ -> putStrLn "retrying accept confirm" >> threadDelay 200000 >> loopConfirm (n + 1)
n <- loopConfirm 1
("", _, A.CONF confId PQSupportOn _ "alice's connInfo") <- get b''
- let waitAck = do
- ServerQueueInfo {info = QueueInfo {qiSize}} <- runRight $ getConnectionQueueInfo b'' NRMInteractive aId
- when (qiSize > 0) $ threadDelay 20000 >> waitAck
- waitAck
+ waitAck b'' aId
pure (n, confId)
("", "", DOWN _ [_]) <- nGet b''
runRight_ $ allowConnection b'' aId confId "bob's connInfo"
withServer1 ps $ do
- ("", "", UP _ [_, _]) <- nGet a'
- get a' ##> ("", bId, A.INFO PQSupportOn "bob's connInfo")
- get a' ##> ("", bId, A.CON PQEncOn)
+ getUpInfoCon a' [contactId, bId] bId "bob's connInfo"
get b'' ##> ("", aId, A.CON PQEncOn) -- note that server 2 is down, this event is delivered when HELLO is sent to server 1
a'' <- restartAgentA restart a' [contactId, bId]
withServer2 ps $ do
@@ -2123,6 +2152,7 @@ testInvitationShortLinkRestart ps = withAgentClients2 $ \a b -> do
newLinkData = UserInvLinkData userData
(bId, CCLink connReq (Just shortLink)) <- withSmpServer ps $
runRight $ A.createConnection a NRMInteractive 1 True True SCMInvitation (Just newLinkData) Nothing CR.IKUsePQ False SMOnlyCreate
+ waitDisconnected a
withSmpServer ps $ do
runRight_ $ subscribeConnection a bId
(_, connData', connReq') <- runRight $ getConnShortLink b 1 shortLink
@@ -2137,6 +2167,7 @@ testContactShortLinkRestart ps = withAgentClients2 $ \a b -> do
newLinkData = UserContactLinkData userCtData
(contactId, CCLink connReq0 (Just shortLink)) <- withSmpServer ps $
runRight $ A.createConnection a NRMInteractive 1 True True SCMContact (Just newLinkData) Nothing CR.IKPQOn False SMOnlyCreate
+ waitDisconnected a
Right connReq <- pure $ smpDecode (smpEncode (binaryConnReq connReq0))
let updatedData = UserLinkData "updated user data"
updatedCtData = UserContactData {direct = False, owners = [], relays = [relayLink1, relayLink2], userData = updatedData, ratchetKeys = Nothing}
@@ -2149,6 +2180,7 @@ testContactShortLinkRestart ps = withAgentClients2 $ \a b -> do
-- update user data
shortLink' <- runRight $ setConnShortLink a contactId SCMContact updatedLinkData Nothing
shortLink' `shouldBe` shortLink
+ waitDisconnected b
withSmpServer ps $ do
(fd4, ContactLinkData _ updatedCtData', _) <- runRight $ getConnShortLink b 1 shortLink
linkConnReq fd4 `shouldBe` connReq
@@ -2162,6 +2194,7 @@ testAddContactShortLinkRestart ps = withAgentClients2 $ \a b -> do
((contactId, CCLink connReq0 Nothing), shortLink) <- withSmpServer ps $ runRight $ do
r@(contactId, _) <- A.createConnection a NRMInteractive 1 True True SCMContact Nothing Nothing CR.IKPQOn False SMOnlyCreate
(r,) <$> setConnShortLink a contactId SCMContact newLinkData Nothing
+ waitDisconnected a
Right connReq <- pure $ smpDecode (smpEncode (binaryConnReq connReq0))
let updatedData = UserLinkData "updated user data"
updatedCtData = UserContactData {direct = False, owners = [], relays = [relayLink1, relayLink2], userData = updatedData, ratchetKeys = Nothing}
@@ -2174,6 +2207,7 @@ testAddContactShortLinkRestart ps = withAgentClients2 $ \a b -> do
-- update user data
shortLink' <- runRight $ setConnShortLink a contactId SCMContact updatedLinkData Nothing
shortLink' `shouldBe` shortLink
+ waitDisconnected b
withSmpServer ps $ do
(fd4, ContactLinkData _ updatedCtData', _) <- runRight $ getConnShortLink b 1 shortLink
linkConnReq fd4 `shouldBe` connReq
@@ -2183,6 +2217,7 @@ testOldContactQueueShortLink :: (HasCallStack, HasTestEnv) => (ASrvTransport, AS
testOldContactQueueShortLink ps@(_, msType) = withAgentClients2 $ \a b -> do
(contactId, CCLink connReq Nothing) <- withSmpServer ps $ runRight $
A.createConnection a NRMInteractive 1 True True SCMContact Nothing Nothing CR.IKPQOn False SMOnlyCreate
+ waitDisconnected a
-- make it an "old" queue
let updateStoreLog f = replaceSubstringInFile f " queue_mode=C" ""
#if defined(dbServerPostgres)
@@ -2527,6 +2562,41 @@ testDuplicateMessage ps = do
disposeAgentClient alice2
disposeAgentClient bob2
+testDuplicateMessageAfterSent :: (HasCallStack, HasTestEnv) => (ASrvTransport, AStoreType) -> IO ()
+testDuplicateMessageAfterSent ps = do
+ alice <- getSMPAgentClient' 1 agentCfg initAgentServers testDB
+ bob <- getSMPAgentClient' 2 agentCfg initAgentServers testDB2
+ withSmpServerStoreMsgLogOn ps testPort $ \_ -> do
+ (aliceId, bobId) <- runRight $ makeConnection alice bob
+ runRight_ $ do
+ 2 <- sendMessage alice bobId SMP.noMsgFlags "hello"
+ get alice ##> ("", bobId, SENT 2)
+ get bob =##> \case ("", c, MSG MsgMeta {integrity = MsgOk, recipient = (2, _), pqEncryption = PQEncOn, redelivered = False} _ "hello") -> c == aliceId; _ -> False
+ 3 <- sendMessage bob aliceId SMP.noMsgFlags "hello too"
+ get bob ##> ("", aliceId, SENT 3)
+ liftIO $ waitDeleted (sndDeliveries bob) (aliceId, 3)
+ disposeAgentClient bob
+ threadDelay 250000
+ bob1 <- getSMPAgentClient' 3 agentCfg initAgentServers testDB2
+ runRight_ $ do
+ subscribeConnection bob1 aliceId
+ get bob1 =##> \case ("", c, MSG MsgMeta {integrity = MsgOk, recipient = (2, _), pqEncryption = PQEncOn, redelivered = True} _ "hello") -> c == aliceId; _ -> False
+ ackMessage bob1 aliceId 2 Nothing
+ disposeAgentClient bob1
+ disposeAgentClient alice
+
+testAckDeletedMessage :: (HasCallStack, HasTestEnv) => IO ()
+testAckDeletedMessage =
+ withAgentClients2 $ \alice bob -> runRight_ $ do
+ (aliceId, bobId) <- makeConnection alice bob
+ 2 <- sendMessage alice bobId SMP.noMsgFlags "hello"
+ get alice ##> ("", bobId, SENT 2)
+ get bob =##> \case ("", c, Msg "hello") -> c == aliceId; _ -> False
+ ackMessage bob aliceId 2 Nothing
+ ackMessage bob aliceId 2 Nothing
+ ackMessageAsync bob "1" aliceId 2 Nothing
+ liftIO $ noMessages bob "nothing else should be delivered to bob"
+
testSkippedMessages :: (HasCallStack, HasTestEnv) => (ASrvTransport, AStoreType) -> IO ()
testSkippedMessages (t, msType) = do
alice <- getSMPAgentClient' 1 agentCfg initAgentServers testDB
@@ -3148,6 +3218,22 @@ processedRatchetKeyHashes c = withTransaction (store $ agentEnv c) (`DB.query_`
sndMessages :: AgentClient -> IO [(ConnId, Int64)]
sndMessages c = withTransaction (store $ agentEnv c) (`DB.query_` "SELECT conn_id, internal_id FROM snd_messages ORDER BY conn_id, internal_id")
+rcvMessages :: AgentClient -> IO [(ConnId, Int64)]
+rcvMessages c = withTransaction (store $ agentEnv c) (`DB.query_` "SELECT conn_id, internal_id FROM rcv_messages ORDER BY conn_id, internal_id")
+
+sndDeliveries :: AgentClient -> IO [(ConnId, Int64)]
+sndDeliveries c = withTransaction (store $ agentEnv c) (`DB.query_` "SELECT conn_id, internal_id FROM snd_message_deliveries ORDER BY conn_id, internal_id")
+
+waitDeleted :: HasCallStack => IO [(ConnId, Int64)] -> (ConnId, Int64) -> IO ()
+waitDeleted getMsgs msg = go (100 :: Int)
+ where
+ go n = do
+ msgs <- getMsgs
+ when (msg `elem` msgs) $
+ if n > 0
+ then threadDelay 100000 >> go (n - 1)
+ else expectationFailure $ "message was not deleted: " <> show msg
+
connInvitations :: AgentClient -> IO [(InvitationId, Maybe ConnId)]
connInvitations c = withTransaction (store $ agentEnv c) (`DB.query_` "SELECT invitation_id, contact_conn_id FROM conn_invitations")
@@ -3942,7 +4028,7 @@ testJoinConnectionAsyncReplyError ps@(t, ASType qsType _) = do
confId <- withSmpServerStoreLogOn ps testPort $ \_ -> do
-- both servers need to be online for connection to progress because of SKEY
get b =##> \case ("2", c, JOINED sqSecured) -> c == aId && sqSecured; _ -> False
- pGet a >>= \case
+ confId <- pGet a >>= \case
("", "", AEvt _ (UP _ [_])) -> do
("", _, CONF confId _ "bob's connInfo") <- get a
pure confId
@@ -3950,6 +4036,8 @@ testJoinConnectionAsyncReplyError ps@(t, ASType qsType _) = do
("", "", UP _ [_]) <- nGet a
pure confId
r -> error $ "unexpected response " <> show r
+ waitAck a bId
+ pure confId
nGet a =##> \case ("", "", DOWN _ [c]) -> c == bId; _ -> False
runRight_ $ do
allowConnectionAsync a "3" bId confId "alice's connInfo"
@@ -4619,6 +4707,63 @@ testDeliveryReceipts =
ackMessage b aId 5 (Just "") `catchError` \case (A.CMD PROHIBITED _) -> pure (); e -> liftIO $ expectationFailure ("unexpected error " <> show e)
ackMessage b aId 5 Nothing
+testDuplicateReceipt :: (HasCallStack, HasTestEnv) => (ASrvTransport, AStoreType) -> Bool -> Bool -> IO ()
+testDuplicateReceipt ps statusLost sentAfter = do
+ alice <- getSMPAgentClient' 1 agentCfg initAgentServers testDB
+ bob <- getSMPAgentClient' 2 agentCfg initAgentServers testDB2
+ withSmpServerStoreMsgLogOn ps testPort $ \_ -> do
+ (aliceId, bobId) <- runRight $ makeConnection alice bob
+ runRight_ $ do
+ 2 <- sendMessage alice bobId SMP.noMsgFlags "hello"
+ get alice ##> ("", bobId, SENT 2)
+ liftIO $ waitDeleted (sndDeliveries alice) (bobId, 2)
+ get bob =##> \case ("", c, Msg "hello") -> c == aliceId; _ -> False
+ ackMessage bob aliceId 2 $ Just ""
+ get alice =##> \case ("", c, RCVD MsgMeta {integrity = MsgOk, redelivered = False} [MsgReceipt {agentMsgId = 2, msgRcptStatus = MROk}]) -> c == bobId; _ -> False
+ when sentAfter $ do
+ 4 <- sendMessage alice bobId SMP.noMsgFlags "hello 2"
+ get alice ##> ("", bobId, SENT 4)
+ liftIO $ waitDeleted (sndDeliveries alice) (bobId, 4)
+ when statusLost $
+ withTransaction (store $ agentEnv alice) (`DB.execute_` "UPDATE snd_messages SET rcpt_internal_id = NULL, rcpt_status = NULL")
+ disposeAgentClient alice
+ threadDelay 250000
+ alice1 <- getSMPAgentClient' 3 agentCfg initAgentServers testDB
+ runRight_ $ do
+ subscribeConnection alice1 bobId
+ get alice1 =##> \case ("", c, RCVD MsgMeta {integrity = MsgOk, redelivered = True} [MsgReceipt {agentMsgId = 2, msgRcptStatus = MROk}]) -> c == bobId; _ -> False
+ ackMessage alice1 bobId 3 Nothing
+ disposeAgentClient alice1
+ disposeAgentClient bob
+
+testReceiptDeletesSentMessage :: (HasCallStack, HasTestEnv) => IO ()
+testReceiptDeletesSentMessage =
+ withAgentClients2 $ \a b -> runRight_ $ do
+ (aId, bId) <- makeConnection a b
+ 2 <- sendMessage a bId SMP.noMsgFlags "hello"
+ get a ##> ("", bId, SENT 2)
+ liftIO $ waitDeleted (sndDeliveries a) (bId, 2)
+ get b =##> \case ("", c, Msg "hello") -> c == aId; _ -> False
+ ackMessage b aId 2 $ Just ""
+ get a =##> \case ("", c, Rcvd 2) -> c == bId; _ -> False
+ ackMessage a bId 3 Nothing
+ liftIO $ sndMessages a >>= (`shouldNotContain` [(bId, 2)])
+
+testReceiptForDeletedSentMessage :: (HasCallStack, HasTestEnv) => IO ()
+testReceiptForDeletedSentMessage =
+ withAgentClients2 $ \a b -> runRight_ $ do
+ (aId, bId) <- makeConnection a b
+ 2 <- sendMessage a bId SMP.noMsgFlags "hello"
+ get a ##> ("", bId, SENT 2)
+ liftIO $ waitDeleted (sndDeliveries a) (bId, 2)
+ get b =##> \case ("", c, Msg "hello") -> c == aId; _ -> False
+ liftIO $ withTransaction (store $ agentEnv a) $ \db -> deleteSndMsgsExpired db 0 100
+ ackMessage b aId 2 $ Just ""
+ mId <- sendMessage b aId SMP.noMsgFlags "hi"
+ get b ##> ("", aId, SENT mId)
+ get a =##> \case ("", c, Msg' 4 PQEncOn "hi") -> c == bId; _ -> False
+ liftIO $ rcvMessages a >>= (`shouldNotContain` [(bId, 3)])
+
testDeliveryReceiptsConcurrent :: (HasCallStack, HasTestEnv) => (ASrvTransport, AStoreType) -> IO ()
testDeliveryReceiptsConcurrent (t, msType) =
withSmpServerConfigOn t cfg' testPort $ \_ -> do
diff --git a/tests/AgentTests/SQLiteTests.hs b/tests/AgentTests/SQLiteTests.hs
index 165df9a58..d1ebb155a 100644
--- a/tests/AgentTests/SQLiteTests.hs
+++ b/tests/AgentTests/SQLiteTests.hs
@@ -586,7 +586,8 @@ mkRcvMsgData internalId internalRcvId externalSndId brokerId internalHash =
recipient = (unId internalId, ts),
sndMsgId = externalSndId,
broker = (SMP.unsafeMsgId $ mconcat (replicate 24 brokerId), ts),
- pqEncryption = CR.PQEncOn
+ pqEncryption = CR.PQEncOn,
+ redelivered = False
},
msgType = AM_A_MSG_,
msgFlags = SMP.noMsgFlags,
diff --git a/tests/SMPProxyTests.hs b/tests/SMPProxyTests.hs
index 59bb14b53..02b87a0e0 100644
--- a/tests/SMPProxyTests.hs
+++ b/tests/SMPProxyTests.hs
@@ -390,9 +390,8 @@ agentViaProxyRetryOffline = do
3 <- msgId <$> A.sendMessage alice bobId pqEnc noMsgFlags msg1
bob `down` aliceId
withServer2 $ \_ -> runRight_ $ do
- bob `up` aliceId
+ withUP bob aliceId $ \case ("", _, Msg' _ pq msg1') -> pq == pqEnc && msg1 == msg1'; _ -> False
get alice ##> ("", bobId, A.SENT (baseId + 3) aProxySrv)
- get bob =##> \case ("", c, Msg' _ pq msg1') -> c == aliceId && pq == pqEnc && msg1 == msg1'; _ -> False
ackMessage bob aliceId (baseId + 3) Nothing
runRight_ $ do
-- proxy relay down
@@ -415,7 +414,6 @@ agentViaProxyRetryOffline = do
withServer_ storeLog storeMsgs storeNtfs =
let cfg' = updateCfg (memoryCfg proxyCfg storeLog storeMsgs) $ \cfg_ -> cfg_ {storeNtfsFile = Just storeNtfs}
in withSmpServerConfigOn (transport @TLS) cfg'
- a `up` cId = nGet a =##> \case ("", "", UP _ [c]) -> c == cId; _ -> False
a `down` cId = nGet a =##> \case ("", "", DOWN _ [c]) -> c == cId; _ -> False
aCfg = agentCfg {messageRetryInterval = fastMessageRetryInterval}
baseId = 1
diff --git a/tests/XFTPServerTests.hs b/tests/XFTPServerTests.hs
index 347bc444d..482d57230 100644
--- a/tests/XFTPServerTests.hs
+++ b/tests/XFTPServerTests.hs
@@ -249,12 +249,12 @@ testInactiveClientExpiration fsType = withXFTPServerConfigOn (updateXFTPCfg (cfg
testCancelledClientConnect :: HasTestEnv => Expectation
testCancelledClientConnect =
- withStallingServerOn' xftpTestPort $ \accepted closed -> do
+ withStallingServerOn' xftpTestPort $ \accepted closed -> replicateM_ 1000 $ do
ts <- getCurrentTime
a <- async $ getXFTPClient (1, testXFTPServer, Nothing) testXFTPClientConfig [] ts (\_ -> pure Nothing) (\_ -> pure ())
timeout 5000000 (atomically $ takeTMVar accepted) `shouldReturn` Just ()
- cancel a
- timeout 1000000 (atomically $ takeTMVar closed) `shouldReturn` Just ()
+ timeout 5000000 (cancel a) `shouldReturn` Just ()
+ timeout 5000000 (atomically $ takeTMVar closed) `shouldReturn` Just ()
testFileStorageQuota :: HasTestEnv => AFStoreType -> Expectation
testFileStorageQuota fsType = withXFTPServerConfigOn (updateXFTPCfg (cfgFS fsType) $ \c -> c {fileSizeQuota = Just $ chSize * 2}) $