Skip to content

Commit

Permalink
integration/testChannelKilled: Kill previous connections to RabbitMQ
Browse files Browse the repository at this point in the history
Merely waiting doesn't seem to work, sometimes there are 4 connections called
"pool 0" in RabbitMQ, possible because those cannons were SIGKILLed.
  • Loading branch information
akshaymankar committed Jan 8, 2025
1 parent 657a46a commit a8d9ba6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions integration/test/Test/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ testChannelKilled = do
-- Some times RabbitMQ still remembers connections from previous uses of the
-- dynamic backend. So we wait to ensure that we kill connection only for our
-- current.
void $ killAllRabbitMqConns backend
waitUntilNoRabbitMqConns backend

runCodensity (startDynamicBackend backend def) $ \_ -> do
Expand Down Expand Up @@ -504,9 +505,10 @@ testChannelKilled = do

-- The RabbitMQ admin API takes some time to see new connections, so we need
-- to try a few times.
recoverAll
(constantDelay 500_000 <> limitRetries 10)
(const (killAllRabbitMqConns backend))
recoverAll (constantDelay 500_000 <> limitRetries 10) $ \_ -> do
conns <- killAllRabbitMqConns backend
assertAtLeastOne conns

waitUntilNoRabbitMqConns backend

assertNoEventHelper ws `shouldMatch` WebSocketDied
Expand Down Expand Up @@ -686,14 +688,14 @@ waitUntilNoRabbitMqConns backend = do
cannonConnections <- getCannonConnections rabbitmqAdminClient backend.berVHost
cannonConnections `shouldMatch` ([] :: [Connection])

-- | Only kills connections from cannon
killAllRabbitMqConns :: (HasCallStack) => BackendResource -> App ()
-- | Only kills connections from cannon and returns them
killAllRabbitMqConns :: (HasCallStack) => BackendResource -> App [Connection]
killAllRabbitMqConns backend = do
rabbitmqAdminClient <- mkRabbitMqAdminClientForResource backend
cannonConnections <- getCannonConnections rabbitmqAdminClient backend.berVHost
assertAtLeastOne cannonConnections
for_ cannonConnections $ \connection ->
rabbitmqAdminClient.deleteConnection connection.name
pure cannonConnections

getCannonConnections :: AdminAPI (AsClientT App) -> String -> App [Connection]
getCannonConnections rabbitmqAdminClient vhost = do
Expand Down

0 comments on commit a8d9ba6

Please sign in to comment.