Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note on race condition in integration test. #2719

Merged
merged 5 commits into from
Sep 23, 2022
Merged
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
3 changes: 2 additions & 1 deletion services/brig/test/integration/API/Provider.hs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,8 @@ testDeleteTeamBotTeam config db brig galley cannon = withTestService config db b
forM_ [uid1, uid2] $ \uid -> do
void $ retryWhileN 20 (/= Intra.Deleted) (getStatus brig uid)
chkStatus brig uid Intra.Deleted
getConversation galley uid cid !!! const 404 === statusCode
eventually $ do
getConversation galley uid cid !!! const 404 === statusCode
-- Check the bot cannot see the conversation either
getBotConv galley bid cid !!! const 404 === statusCode

Expand Down
4 changes: 4 additions & 0 deletions services/brig/test/integration/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,10 @@ aFewTimes
(\_ -> pure . not . good)
(const action)

-- see also: `aFewTimes`. we should really clean this up.
eventually :: (MonadIO m, MonadMask m) => m a -> m a
eventually = recovering (limitRetries 3 <> exponentialBackoff 100000) [] . const

assertOne :: (HasCallStack, MonadIO m, Show a) => [a] -> m a
assertOne [a] = pure a
assertOne xs = liftIO . assertFailure $ "Expected exactly one element, found " <> show xs
Expand Down
5 changes: 1 addition & 4 deletions services/galley/test/integration/API/Teams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import qualified Brig.Types.Intra as Brig
import Control.Arrow ((>>>))
import Control.Lens hiding ((#), (.=))
import Control.Monad.Catch
import Control.Retry
import Data.Aeson hiding (json)
import Data.ByteString.Conversion
import Data.ByteString.Lazy (fromStrict)
Expand Down Expand Up @@ -75,7 +74,7 @@ import Test.Tasty
import Test.Tasty.Cannon (TimeoutUnit (..), (#))
import qualified Test.Tasty.Cannon as WS
import Test.Tasty.HUnit
import TestHelpers (test, viewFederationDomain)
import TestHelpers (eventually, test, viewFederationDomain)
import TestSetup (TestM, TestSetup, tsBrig, tsCannon, tsGConf, tsGalley)
import UnliftIO (mapConcurrently)
import Wire.API.Conversation
Expand Down Expand Up @@ -491,8 +490,6 @@ testCreateOne2OneWithMembers (rolePermissions -> perms) = do
-- | At the time of writing this test, the only event sent to this queue is 'MemberJoin'.
testTeamQueue :: TestM ()
testTeamQueue = do
let eventually = recovering (limitRetries 3 <> exponentialBackoff 100000) [] . const

(owner, tid) <- createBindingTeam
eventually $ do
queue <- getTeamQueue owner Nothing Nothing False
Expand Down
8 changes: 4 additions & 4 deletions services/galley/test/integration/API/Teams/Feature.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import Test.QuickCheck (Gen, generate, suchThat)
import Test.Tasty
import qualified Test.Tasty.Cannon as WS
import Test.Tasty.HUnit (assertFailure, (@?=))
import TestHelpers (test)
import TestHelpers (eventually, test)
import TestSetup
import Wire.API.Conversation.Protocol (ProtocolTag (ProtocolMLSTag, ProtocolProteusTag))
import qualified Wire.API.Event.FeatureConfig as FeatureConfig
Expand Down Expand Up @@ -495,17 +495,17 @@ testSimpleFlagTTLOverride defaultValue ttl ttlAfter = do
nonMember <- Util.randomUser

let getFlag :: HasCallStack => Public.FeatureStatus -> TestM ()
getFlag expected =
getFlag expected = eventually $ do
flip (assertFlagNoConfig @cfg) expected $ Util.getTeamFeatureFlag @cfg member tid

getFeatureConfig :: HasCallStack => Public.FeatureStatus -> FeatureTTL -> TestM ()
getFeatureConfig expectedStatus expectedTtl = do
getFeatureConfig expectedStatus expectedTtl = eventually $ do
actual <- Util.getFeatureConfig @cfg member
liftIO $ Public.wsStatus actual @?= expectedStatus
liftIO $ Public.wsTTL actual @?= expectedTtl

getFlagInternal :: HasCallStack => Public.FeatureStatus -> TestM ()
getFlagInternal expected =
getFlagInternal expected = eventually $ do
flip (assertFlagNoConfig @cfg) expected $ Util.getTeamFeatureFlagInternal @cfg tid

setFlagInternal :: Public.FeatureStatus -> FeatureTTL -> TestM ()
Expand Down
5 changes: 5 additions & 0 deletions services/galley/test/integration/TestHelpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module TestHelpers where

import API.SQS
import Control.Lens (view)
import Control.Monad.Catch (MonadMask)
import Control.Retry
import Data.Domain (Domain)
import Data.Qualified
import qualified Galley.Aws as Aws
Expand Down Expand Up @@ -60,3 +62,6 @@ qualifyLocal :: a -> TestM (Local a)
qualifyLocal x = do
domain <- viewFederationDomain
pure $ toLocalUnsafe domain x

eventually :: (MonadIO m, MonadMask m) => m a -> m a
eventually = recovering (limitRetries 3 <> exponentialBackoff 100000) [] . const