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
15 changes: 3 additions & 12 deletions libs/types-common-aws/src/Util/Test/SQS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ data SQSWatcher a = SQSWatcher
-- This function drops everything in the queue before starting the async loop.
-- This helps test run faster and makes sure that initial tests don't timeout if
-- the queue has too many things in it before the tests start.
-- Note that the purgeQueue command is not guaranteed to be instant (can take up to 60 seconds)
-- Hopefully, the fake-aws implementation used during tests is fast enough.
watchSQSQueue :: Message a => AWS.Env -> Text -> IO (SQSWatcher a)
watchSQSQueue env queueUrl = do
eventsRef <- newIORef []
Expand All @@ -73,18 +75,7 @@ watchSQSQueue env queueUrl = do
recieveLoop ref

ensureEmpty :: IO ()
ensureEmpty = do
let rcvReq =
SQS.newReceiveMessage queueUrl
& set SQS.receiveMessage_waitTimeSeconds (Just 1)
. set SQS.receiveMessage_maxNumberOfMessages (Just 10) -- 10 is maximum allowed by AWS
. set SQS.receiveMessage_visibilityTimeout (Just 1)
rcvRes <- execute env $ sendEnv rcvReq
case fromMaybe [] $ view SQS.receiveMessageResponse_messages rcvRes of
[] -> pure ()
ms -> do
execute env $ mapM_ (deleteMessage queueUrl) ms
ensureEmpty
ensureEmpty = void $ execute env $ sendEnv (SQS.newPurgeQueue queueUrl)

-- | Waits for a message matching a predicate for a given number of seconds.
waitForMessage :: (MonadUnliftIO m, Eq a, Show a) => SQSWatcher a -> Int -> (a -> Bool) -> m (Maybe a)
Expand Down