@@ -480,6 +480,7 @@ functionalAPITests ps = do
480480 describe " Client service certificates" $ do
481481 it " should connect, subscribe and reconnect as a service" $ testClientServiceConnection ps
482482 it " should re-subscribe when service ID changed" $ testClientServiceIDChange ps
483+ it " migrate connections to and from service" $ testMigrateConnectionsToService ps
483484 describe " Connection switch" $ do
484485 describe " should switch delivery to the new queue" $
485486 testServerMatrix2 ps testSwitchConnection
@@ -3743,7 +3744,7 @@ testClientServiceIDChange ps@(_, ASType qs _) = do
37433744 liftIO $ getInAnyOrder service
37443745 [ \ case (" " , " " , AEvt SAENone (SERVICE_UP _ (SMP. ServiceSubResult (Just (SMP. SSErrorQueueCount 1 0 )) (SMP. ServiceSub _ 0 _)))) -> True ; _ -> False ,
37453746 \ case (" " , " " , AEvt SAENone (SERVICE_ALL _)) -> True ; _ -> False ,
3746- \ case (" " , " " , AEvt SAENone (UP _ _ )) -> True ; _ -> False
3747+ \ case (" " , " " , AEvt SAENone (UP _ [_] )) -> True ; _ -> False
37473748 ]
37483749 subscribeAllConnections user False Nothing
37493750 (" " , " " , UP _ [_]) <- nGet user
@@ -3759,6 +3760,159 @@ testClientServiceIDChange ps@(_, ASType qs _) = do
37593760 (" " , " " , UP _ [_]) <- nGet user
37603761 exchangeGreetingsMsgId 6 notService uId user sId
37613762
3763+ testMigrateConnectionsToService :: HasCallStack => (ASrvTransport , AStoreType ) -> IO ()
3764+ testMigrateConnectionsToService ps = do
3765+ (((sId1, uId1), (uId2, sId2)), ((sId3, uId3), (uId4, sId4)), ((sId5, uId5), (uId6, sId6))) <-
3766+ withSmpServerStoreLogOn ps testPort $ \ _ -> do
3767+ -- starting without service
3768+ cs12@ ((sId1, uId1), (uId2, sId2)) <-
3769+ withAgentClientsServers2 (agentCfg, initAgentServers) (agentCfg, initAgentServers) $ \ notService user ->
3770+ runRight $ (,) <$> makeConnection notService user <*> makeConnection user notService
3771+ -- migrating to service
3772+ cs34@ ((sId3, uId3), (uId4, sId4)) <-
3773+ withAgentClientsServers2 (agentCfg, initAgentServersClientService) (agentCfg, initAgentServers) $ \ service user -> runRight $ do
3774+ subscribeAllConnections service False Nothing
3775+ service `up` 2
3776+ subscribeAllConnections user False Nothing
3777+ user `up` 2
3778+ exchangeGreetingsMsgId 2 service uId1 user sId1
3779+ exchangeGreetingsMsgId 2 service uId2 user sId2
3780+ (,) <$> makeConnection service user <*> makeConnection user service
3781+ -- starting as service
3782+ cs56 <-
3783+ withAgentClientsServers2 (agentCfg, initAgentServersClientService) (agentCfg, initAgentServers) $ \ service user -> runRight $ do
3784+ subscribeAllConnections service False Nothing
3785+ liftIO $ getInAnyOrder service
3786+ [ \ case (" " , " " , AEvt SAENone (SERVICE_UP _ (SMP. ServiceSubResult Nothing (SMP. ServiceSub _ 4 _)))) -> True ; _ -> False ,
3787+ \ case (" " , " " , AEvt SAENone (SERVICE_ALL _)) -> True ; _ -> False
3788+ ]
3789+ subscribeAllConnections user False Nothing
3790+ user `up` 4
3791+ exchangeGreetingsMsgId 4 service uId1 user sId1
3792+ exchangeGreetingsMsgId 4 service uId2 user sId2
3793+ exchangeGreetingsMsgId 2 service uId3 user sId3
3794+ exchangeGreetingsMsgId 2 service uId4 user sId4
3795+ (,) <$> makeConnection service user <*> makeConnection user service
3796+ pure (cs12, cs34, cs56)
3797+ -- server reconnecting resubscribes service
3798+ let testSendMessages6 s u n = do
3799+ exchangeGreetingsMsgId (n + 4 ) s uId1 u sId1
3800+ exchangeGreetingsMsgId (n + 4 ) s uId2 u sId2
3801+ exchangeGreetingsMsgId (n + 2 ) s uId3 u sId3
3802+ exchangeGreetingsMsgId (n + 2 ) s uId4 u sId4
3803+ exchangeGreetingsMsgId n s uId5 u sId5
3804+ exchangeGreetingsMsgId n s uId6 u sId6
3805+ withAgentClientsServers2 (agentCfg, initAgentServersClientService) (agentCfg, initAgentServers) $ \ service user -> do
3806+ withSmpServerStoreLogOn ps testPort $ \ _ -> runRight_ $ do
3807+ subscribeAllConnections service False Nothing
3808+ liftIO $ getInAnyOrder service
3809+ [ \ case (" " , " " , AEvt SAENone (SERVICE_UP _ (SMP. ServiceSubResult Nothing (SMP. ServiceSub _ 6 _)))) -> True ; _ -> False ,
3810+ \ case (" " , " " , AEvt SAENone (SERVICE_ALL _)) -> True ; _ -> False
3811+ ]
3812+ subscribeAllConnections user False Nothing
3813+ user `up` 6
3814+ testSendMessages6 service user 2
3815+ (" " , " " , SERVICE_DOWN _ (SMP. ServiceSub _ 6 _)) <- nGet service
3816+ user `down` 6
3817+ withSmpServerStoreLogOn ps testPort $ \ _ -> runRight_ $ do
3818+ liftIO $ getInAnyOrder service
3819+ [ \ case (" " , " " , AEvt SAENone (SERVICE_UP _ (SMP. ServiceSubResult Nothing (SMP. ServiceSub _ 6 _)))) -> True ; _ -> False ,
3820+ \ case (" " , " " , AEvt SAENone (SERVICE_ALL _)) -> True ; _ -> False
3821+ ]
3822+ user `up` 6
3823+ testSendMessages6 service user 4
3824+ (" " , " " , SERVICE_DOWN _ (SMP. ServiceSub _ 6 _)) <- nGet service
3825+ user `down` 6
3826+ -- disabling service and adding connections
3827+ ((sId7, uId7), (uId8, sId8)) <-
3828+ withAgentClientsServers2 (agentCfg, initAgentServers) (agentCfg, initAgentServers) $ \ notService user -> do
3829+ cs78@ ((sId7, uId7), (uId8, sId8)) <-
3830+ withSmpServerStoreLogOn ps testPort $ \ _ -> runRight $ do
3831+ subscribeAllConnections notService False Nothing
3832+ notService `up` 6
3833+ subscribeAllConnections user False Nothing
3834+ user `up` 6
3835+ testSendMessages6 notService user 6
3836+ (,) <$> makeConnection notService user <*> makeConnection user notService
3837+ notService `down` 8
3838+ user `down` 8
3839+ withSmpServerStoreLogOn ps testPort $ \ _ -> runRight $ do
3840+ notService `up` 8
3841+ user `up` 8
3842+ testSendMessages6 notService user 8
3843+ exchangeGreetingsMsgId 2 notService uId7 user sId7
3844+ exchangeGreetingsMsgId 2 notService uId8 user sId8
3845+ notService `down` 8
3846+ user `down` 8
3847+ pure cs78
3848+ let testSendMessages8 s u n = do
3849+ testSendMessages6 s u (n + 8 )
3850+ exchangeGreetingsMsgId (n + 2 ) s uId7 u sId7
3851+ exchangeGreetingsMsgId (n + 2 ) s uId8 u sId8
3852+ -- re-enabling service and adding connections
3853+ withAgentClientsServers2 (agentCfg, initAgentServersClientService) (agentCfg, initAgentServers) $ \ service user -> do
3854+ withSmpServerStoreLogOn ps testPort $ \ _ -> runRight_ $ do
3855+ subscribeAllConnections service False Nothing
3856+ -- the "error" in SERVICE_UP event is expected, because when service was disabled for the user,
3857+ -- the service and associations were not removed, to optimize non-service clients.
3858+ liftIO $ getInAnyOrder service
3859+ [ \ case (" " , " " , AEvt SAENone (SERVICE_UP _ (SMP. ServiceSubResult (Just (SMP. SSErrorQueueCount 6 0 )) (SMP. ServiceSub _ 0 _)))) -> True ; _ -> False ,
3860+ \ case (" " , " " , AEvt SAENone (SERVICE_ALL _)) -> True ; _ -> False
3861+ ]
3862+ service `up` 8
3863+ subscribeAllConnections user False Nothing
3864+ user `up` 8
3865+ testSendMessages8 service user 2
3866+ (" " , " " , SERVICE_DOWN _ (SMP. ServiceSub _ 8 _)) <- nGet service
3867+ user `down` 8
3868+ -- re-connect to server
3869+ withSmpServerStoreLogOn ps testPort $ \ _ -> runRight_ $ do
3870+ liftIO $ getInAnyOrder service
3871+ [ \ case (" " , " " , AEvt SAENone (SERVICE_UP _ (SMP. ServiceSubResult Nothing (SMP. ServiceSub _ 8 _)))) -> True ; _ -> False ,
3872+ \ case (" " , " " , AEvt SAENone (SERVICE_ALL _)) -> True ; _ -> False
3873+ ]
3874+ user `up` 8
3875+ testSendMessages8 service user 4
3876+ (" " , " " , SERVICE_DOWN _ (SMP. ServiceSub _ _ _)) <- nGet service -- should be 8 here
3877+ user `down` 8
3878+ -- restart agents
3879+ withAgentClientsServers2 (agentCfg, initAgentServersClientService) (agentCfg, initAgentServers) $ \ service user -> do
3880+ withSmpServerStoreLogOn ps testPort $ \ _ -> runRight_ $ do
3881+ subscribeAllConnections service False Nothing
3882+ liftIO $ getInAnyOrder service
3883+ [ \ case (" " , " " , AEvt SAENone (SERVICE_UP _ (SMP. ServiceSubResult Nothing (SMP. ServiceSub _ 8 _)))) -> True ; _ -> False ,
3884+ \ case (" " , " " , AEvt SAENone (SERVICE_ALL _)) -> True ; _ -> False
3885+ ]
3886+ subscribeAllConnections user False Nothing
3887+ user `up` 8
3888+ testSendMessages8 service user 6
3889+ (" " , " " , SERVICE_DOWN _ (SMP. ServiceSub _ 8 _)) <- nGet service
3890+ user `down` 8
3891+ runRight_ $ do
3892+ void $ sendMessage user sId7 SMP. noMsgFlags " hello 1"
3893+ void $ sendMessage user sId8 SMP. noMsgFlags " hello 2"
3894+ -- re-connect to server
3895+ withSmpServerStoreLogOn ps testPort $ \ _ -> runRight_ $ do
3896+ liftIO $ getInAnyOrder service
3897+ [ \ case (" " , " " , AEvt SAENone (SERVICE_UP _ (SMP. ServiceSubResult Nothing (SMP. ServiceSub _ 8 _)))) -> True ; _ -> False ,
3898+ \ case (" " , c, AEvt SAEConn (Msg " hello 1" )) -> c == uId7; _ -> False ,
3899+ \ case (" " , c, AEvt SAEConn (Msg " hello 2" )) -> c == uId8; _ -> False ,
3900+ \ case (" " , " " , AEvt SAENone (SERVICE_ALL _)) -> True ; _ -> False
3901+ ]
3902+ liftIO $ getInAnyOrder user
3903+ [ \ case (" " , " " , AEvt SAENone (UP _ [_, _, _, _, _, _, _, _])) -> True ; _ -> False ,
3904+ \ case (" " , c, AEvt SAEConn (SENT 10 )) -> c == sId7; _ -> False ,
3905+ \ case (" " , c, AEvt SAEConn (SENT 10 )) -> c == sId8; _ -> False
3906+ ]
3907+ testSendMessages6 service user 16
3908+ where
3909+ up c n = do
3910+ (" " , " " , UP _ conns) <- nGet c
3911+ liftIO $ length conns `shouldBe` n
3912+ down c n = do
3913+ (" " , " " , DOWN _ conns) <- nGet c
3914+ liftIO $ length conns `shouldBe` n
3915+
37623916getSMPAgentClient' :: Int -> AgentConfig -> InitialAgentServers -> String -> IO AgentClient
37633917getSMPAgentClient' clientId cfg' initServers dbPath = do
37643918 Right st <- liftIO $ createStore dbPath
0 commit comments