Skip to content
Merged
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
37 changes: 37 additions & 0 deletions tests/AgentTests/FunctionalAPITests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ functionalAPITests ps = do
it "should re-subscribe when service ID changed" $ testClientServiceIDChange ps
it "should clear pending service sub when service unavailable" $ testServiceUnavailableClearsPending ps
it "should recover when service ID changes on reconnect" $ testServiceIdChangeOnReconnect ps
it "should handle service unavailable on startup" $ testServiceUnavailableOnStartup ps
it "migrate connections to and from service" $ testMigrateConnectionsToService ps
describe "Connection switch" $ do
describe "should switch delivery to the new queue" $
Expand Down Expand Up @@ -3997,6 +3998,42 @@ testServiceIdChangeOnReconnect ps@(_, ASType qs _) = do
("", "", UP _ [_]) <- nGet user
pure ()

-- | Test that subscribeAllConnections handles service unavailable on startup.
-- Agent has service credentials but server doesn't support services (askClientCert = False).
testServiceUnavailableOnStartup :: HasCallStack => (ASrvTransport, AStoreType) -> IO ()
testServiceUnavailableOnStartup (t, msType) = do
let srv = initAgentServersClientService
noSrv = initAgentServers
-- Phase 1: Establish connection with service
(sId, uId) <- withAgentClientsServers2 (agentCfg, srv) (agentCfg, noSrv) $ \service user ->
withSmpServerStoreLogOn (t, msType) testPort $ \_ -> runRight $ do
conns@(sId, uId) <- makeConnection service user
exchangeGreetings service uId user sId
pure conns
-- Phase 2: Server without service support, new service agent
let cfgNoService = updateCfg (cfgMS msType) $ \(cfg' :: ServerConfig s) ->
let ServerConfig {transportConfig} = cfg'
in cfg' {transportConfig = transportConfig {askClientCert = False}} :: ServerConfig s
-- Phase 2: Server without service support, service agent gets NO_SERVICE
withAgentClientsServers2 (agentCfg, srv) (agentCfg, noSrv) $ \service user ->
withSmpServerConfigOn t cfgNoService testPort $ \_ -> runRight $ do
subscribeAllConnections service False Nothing
("", "", ERR (BROKER _ NO_SERVICE)) <- get service
("", "", UP _ [_]) <- nGet service
subscribeAllConnections user False Nothing
("", "", UP _ [_]) <- nGet user
exchangeGreetingsMsgId 4 service uId user sId
-- Phase 3: Normal server - cert was deleted, new cert generated,
-- no service sub in DB yet, queues subscribed individually
withAgentClientsServers2 (agentCfg, srv) (agentCfg, noSrv) $ \service user ->
withSmpServerStoreLogOn (t, msType) testPort $ \_ -> runRight $ do
liftIO $ threadDelay 250000
subscribeAllConnections service False Nothing
("", "", UP _ [_]) <- nGet service
subscribeAllConnections user False Nothing
("", "", UP _ [_]) <- nGet user
exchangeGreetingsMsgId 6 service uId user sId

testMigrateConnectionsToService :: HasCallStack => (ASrvTransport, AStoreType) -> IO ()
testMigrateConnectionsToService ps = do
(((sId1, uId1), (uId2, sId2)), ((sId3, uId3), (uId4, sId4)), ((sId5, uId5), (uId6, sId6))) <-
Expand Down
Loading