Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Simplex/Messaging/Agent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,8 @@ deleteUser' c@AgentClient {smpServersStats, xftpServersStats} userId delSMPQueue
lift $ saveServersStats c
where
delUser =
whenM (withStore' c (`deleteUserWithoutConns` userId)) . atomically $
writeTBQueue (subQ c) ("", "", AEvt SAENone $ DEL_USER userId)
whenM (withStore' c (`deleteUserWithoutConns` userId)) . liftIO $
nonBlockingWriteTBQueue (subQ c) ("", "", AEvt SAENone $ DEL_USER userId)

setUserService' :: AgentClient -> UserId -> Bool -> AM ()
setUserService' c userId enable = do
Expand Down Expand Up @@ -3063,7 +3063,7 @@ prepareDeleteConnections_ getConnections c waitDelivery connIds = do
unsubNtfConnIds connIds' = do
ns <- asks ntfSupervisor
atomically $ writeTBQueue (ntfSubQ ns) (NSCDeleteSub, connIds')
notify = atomically . writeTBQueue (subQ c)
notify = liftIO . nonBlockingWriteTBQueue (subQ c)

deleteConnQueues :: AgentClient -> NetworkRequestMode -> Bool -> Bool -> [RcvQueue] -> AM' (Map ConnId (Either AgentErrorType ()))
deleteConnQueues c nm waitDelivery ntf rqs = do
Expand Down
29 changes: 28 additions & 1 deletion tests/AgentTests/FunctionalAPITests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ import Simplex.Messaging.Server.QueueStore.QueueInfo
import Simplex.Messaging.Server.StoreLog (StoreLogRecord (..))
import Simplex.Messaging.Transport (ASrvTransport, SMPVersion, VersionSMP, currentServerSMPRelayVersion, minClientSMPRelayVersion, minServerSMPRelayVersion, alpnSupportedSMPHandshakes)
import Simplex.Messaging.Transport.Server (TransportServerConfig (..))
import Simplex.Messaging.Util (bshow, diffToMicroseconds)
import Simplex.Messaging.Util (bshow, diffToMicroseconds, unlessM)
import Simplex.Messaging.Version (VersionRange (..))
import qualified Simplex.Messaging.Version as V
import Simplex.Messaging.Version.Internal (Version (..))
Expand Down Expand Up @@ -557,6 +557,8 @@ functionalAPITests ps = do
testBasicMatrix2 ps testAcceptContactAsync
it "should delete connections using async command when server connection fails" $
testDeleteConnectionAsync ps
it "should delete connection without receive queue when event queue is full" $
testDeleteConnectionAsyncFullQueue
it "join connection when reply queue creation fails" $
testJoinConnectionAsyncReplyError ps
describe "delete connection waiting for delivery" $ do
Expand All @@ -575,6 +577,8 @@ functionalAPITests ps = do
withSmpServer ps testUsers
it "should create and delete user without connections" $
withSmpServer ps testDeleteUserQuietly
it "should delete user without connections when event queue is full" $
testDeleteUserFullQueue
it "should create and delete user with connections when server connection fails" $
testUsersNoServer ps
it "should connect two users and switch session mode" $
Expand Down Expand Up @@ -3760,6 +3764,20 @@ testDeleteConnectionAsync ps =
get a =##> \case ("", "", DEL_CONNS cs) -> length cs == 3 && all (`elem` connIds) cs; _ -> False
liftIO $ noMessages a "nothing else should be delivered to alice"

testDeleteConnectionAsyncFullQueue :: HasTestEnv => IO ()
testDeleteConnectionAsyncFullQueue =
withAgent 1 agentCfg initAgentServers testDB $ \a -> do
(connId, _) <- runRight $ A.prepareConnectionToJoin a 1 True (CRInvitationUri connReqData testE2ERatchetParams12) PQSupportOn
fillSubQ a
timeout 5000000 (runExceptT $ deleteConnectionsAsync a False [connId]) `shouldReturn` Just (Right ())
void . atomically . flushTBQueue $ subQ a
get a =##> \case ("", "", DEL_CONNS [c]) -> c == connId; _ -> False

fillSubQ :: AgentClient -> IO ()
fillSubQ c = atomically fill
where
fill = unlessM (isFullTBQueue $ subQ c) $ writeTBQueue (subQ c) ("", "", AEvt SAENone SUSPENDED) >> fill

testWaitDeliveryNoPending :: HasTestEnv => (ASrvTransport, AStoreType) -> IO ()
testWaitDeliveryNoPending ps = withAgentClients2 $ \alice bob ->
withSmpServerStoreLogOn ps testPort $ \_ -> runRight_ $ do
Expand Down Expand Up @@ -4051,6 +4069,15 @@ testDeleteUserQuietly =
exchangeGreetingsMsgId 4 a bId b aId
liftIO $ noMessages a "nothing else should be delivered to alice"

testDeleteUserFullQueue :: HasTestEnv => IO ()
testDeleteUserFullQueue =
withAgent 1 agentCfg initAgentServers testDB $ \a -> do
auId <- runRight $ createUser a False [noAuthSrvCfg testSMPServer] [noAuthSrvCfg testXFTPServer]
fillSubQ a
timeout 5000000 (runExceptT $ deleteUser a auId True) `shouldReturn` Just (Right ())
void . atomically . flushTBQueue $ subQ a
nGet a =##> \case ("", "", DEL_USER u) -> u == auId; _ -> False

testUsersNoServer :: (HasCallStack, HasTestEnv) => (ASrvTransport, AStoreType) -> IO ()
testUsersNoServer ps = withAgentClientsCfg2 aCfg agentCfg $ \a b -> do
(aId, bId, auId, _aId', bId') <- withSmpServerStoreLogOn ps testPort $ \_ -> runRight $ do
Expand Down
Loading