diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index b729c7bd9..9c1185ab2 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -2130,6 +2130,7 @@ enqueueConfirmation c cData@ConnData {connId, connAgentVersion} sq connInfo e2eE msgType = agentMessageType agentMsg msgData = SndMsgData {internalId, internalSndId, internalTs, msgType, msgBody, msgFlags = SMP.MsgFlags {notification = True}, internalHash, prevMsgHash} liftIO $ createSndMsg db connId msgData + liftIO $ createSndMsgDelivery db connId sq internalId pure internalId -- encoded AgentMessage -> encoded EncAgentMessage diff --git a/tests/AgentTests/FunctionalAPITests.hs b/tests/AgentTests/FunctionalAPITests.hs index df0d9dfb5..c95d8f304 100644 --- a/tests/AgentTests/FunctionalAPITests.hs +++ b/tests/AgentTests/FunctionalAPITests.hs @@ -160,6 +160,8 @@ functionalAPITests t = do testAsyncServerOffline t it "should notify after HELLO timeout" $ withSmpServer t testAsyncHelloTimeout + it "should restore confirmation after client restart" $ + testAllowConnectionClientRestart t describe "Message delivery" $ do it "should deliver message after client restart" $ testDeliverClientRestart t @@ -475,6 +477,44 @@ testAsyncHelloTimeout = do aliceId <- joinConnection bob 1 True cReq "bob's connInfo" get bob ##> ("", aliceId, ERR $ CONN NOT_ACCEPTED) +testAllowConnectionClientRestart :: HasCallStack => ATransport -> IO () +testAllowConnectionClientRestart t = do + let initAgentServersSrv2 = initAgentServers {smp = userServers [noAuthSrv testSMPServer2]} + alice <- getSMPAgentClient' agentCfg initAgentServers testDB + bob <- getSMPAgentClient' agentCfg initAgentServersSrv2 testDB2 + withSmpServerStoreLogOn t testPort $ \_ -> do + (aliceId, bobId, confId) <- + withSmpServerConfigOn t cfg {storeLogFile = Just testStoreLogFile2} testPort2 $ \_ -> do + runRight $ do + (bobId, qInfo) <- createConnection alice 1 True SCMInvitation Nothing + aliceId <- joinConnection bob 1 True qInfo "bob's connInfo" + ("", _, CONF confId _ "bob's connInfo") <- get alice + pure (aliceId, bobId, confId) + + ("", "", DOWN _ _) <- nGet bob + + runRight_ $ do + allowConnectionAsync alice "1" bobId confId "alice's connInfo" + ("1", _, OK) <- get alice + pure () + + threadDelay 100000 -- give time to enqueue confirmation (enqueueConfirmation) + disconnectAgentClient alice + + alice2 <- getSMPAgentClient' agentCfg initAgentServers testDB + + withSmpServerConfigOn t cfg {storeLogFile = Just testStoreLogFile2} testPort2 $ \_ -> do + runRight $ do + ("", "", UP _ _) <- nGet bob + + subscribeConnection alice2 bobId + + get alice2 ##> ("", bobId, CON) + get bob ##> ("", aliceId, INFO "alice's connInfo") + get bob ##> ("", aliceId, CON) + + exchangeGreetingsMsgId 4 alice2 bobId bob aliceId + testDeliverClientRestart :: HasCallStack => ATransport -> IO () testDeliverClientRestart t = do alice <- getSMPAgentClient' agentCfg initAgentServers testDB