Skip to content
Closed
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
1 change: 1 addition & 0 deletions changelog.d/5-internal/perhaps-deflake-search-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Attempt to deflake a flaky integration test about search
23 changes: 13 additions & 10 deletions services/brig/test/integration/API/Search.hs
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ testOrderName brig = do
nameMatch <- userQualifiedId <$> createUser' True searchedWord brig
namePrefixMatch <- userQualifiedId <$> createUser' True (searchedWord <> "suffix") brig
refreshIndex brig
results <- searchResults <$> executeSearch brig searcher searchedWord
let resultUIds = map contactQualifiedId results
let expectedOrder = [nameMatch, namePrefixMatch]
let dbg = "results: " <> show results <> "\nsearchedWord: " <> cs searchedWord
-- possibly there is some delay in refreshing of the index writes being
-- visible for subsequent reads, so we try this a few times.
results <- aFewTimes 12 (toIds <$> executeSearch brig searcher searchedWord) (== expectedOrder)
liftIO $
assertEqual
("Expected order: name match, name prefix match.\n\nSince this test fails sporadically for unknown reasons here is some debug info:\n" <> dbg)
"If this test fails again, maybe we should consider deleting it and living with some more uncertainty"
expectedOrder
resultUIds
results
Comment on lines +267 to +274
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't actually fix the test. The problem is in the production code. So, if you really want to fix it by running again, you should generate the name again.


testOrderHandle :: TestConstraints m => Brig -> m ()
testOrderHandle brig = do
Expand All @@ -282,15 +282,18 @@ testOrderHandle brig = do
handlePrefixMatch <- userQualifiedId <$> createUser' True "handle prefix match" brig
void $ putHandle brig (qUnqualified handlePrefixMatch) (searchedWord <> "suffix")
refreshIndex brig
results <- searchResults <$> executeSearch brig searcher searchedWord
let resultUIds = map contactQualifiedId results
let expectedOrder = [handleMatch, handlePrefixMatch]
let dbg = "results: " <> show results <> "\nsearchedWord: " <> cs searchedWord
-- possibly there is some delay in refreshing of the index writes being
-- visible for subsequent reads, so we try this a few times.
results <- aFewTimes 12 (toIds <$> executeSearch brig searcher searchedWord) (== expectedOrder)
liftIO $
assertEqual
("Expected order: handle match, handle prefix match.\n\nSince this test fails sporadically for unknown reasons here here is some debug info:\n" <> dbg)
"If this test fails again, maybe we should consider deleting it and living with some more uncertainty"
expectedOrder
resultUIds
results
Comment on lines -285 to +293
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not broken anymore. The comment is stale.


toIds :: SearchResult Contact -> [Qualified UserId]
toIds = map contactQualifiedId . searchResults

testSearchTeamMemberAsNonMemberDisplayName :: TestConstraints m => Brig -> m ()
testSearchTeamMemberAsNonMemberDisplayName brig = do
Expand Down
18 changes: 0 additions & 18 deletions services/brig/test/integration/API/UserPendingActivation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import Control.Exception (assert)
import Control.Lens ((^.), (^?))
import Control.Monad.Catch (MonadCatch)
import Control.Monad.Random
import Control.Retry (exponentialBackoff, limitRetries, retrying)
import Data.Aeson hiding (json)
import qualified Data.Aeson as Aeson
import Data.Aeson.Lens (key, _String)
Expand Down Expand Up @@ -363,20 +362,3 @@ acceptWithName name email code =
"password" Aeson..= defPassword,
"team_code" Aeson..= code
]

-- | Run a probe several times, until a "good" value materializes or until patience runs out
aFewTimes ::
(HasCallStack, MonadIO m) =>
-- | Number of retries. Exponentially: 11 ~ total of 2 secs delay, 12 ~ 4 secs delay, ...
Int ->
m a ->
(a -> Bool) ->
m a
aFewTimes
retries
action
good = do
retrying
(exponentialBackoff 1000 <> limitRetries retries)
(\_ -> pure . not . good)
(\_ -> action)
17 changes: 17 additions & 0 deletions services/brig/test/integration/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,23 @@ recoverN n m =
(constantDelay 1000000 <> limitRetries n)
(const m)

-- | Run a probe several times, until a "good" value materializes or until patience runs out
aFewTimes ::
(HasCallStack, MonadIO m) =>
-- | Number of retries. Exponentially: 11 ~ total of 2 secs delay, 12 ~ 4 secs delay, ...
Int ->
m a ->
(a -> Bool) ->
m a
aFewTimes
retries
action
good = do
retrying
(exponentialBackoff 1000 <> limitRetries retries)
(\_ -> pure . not . good)
(\_ -> action)

-- | This allows you to run requests against a brig instantiated using the given options.
-- Note that ONLY 'brig' calls should occur within the provided action, calls to other
-- services will fail.
Expand Down