Reduce duplication of mock https servers in integration tests.
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 2.8k
- Forks
- 334
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 50
Description
There are a number of functions that create https servers for integration tests:
- https://github.com/wireapp/wire-server/blob/b266f9aae3ee8bf31ac83413b7e7f37feb8aa488/services/brig/test/integration/API/Provider.hs#L1519-L1531
- https://github.com/wireapp/wire-server/blob/b266f9aae3ee8bf31ac83413b7e7f37feb8aa488/services/galley/test/integration/API/Teams/LegalHold.hs#L805-L825
- ...? (
git grep -Hn runTLSsuggests these are the only ones)
The following variant has more sophisticated error reporting, but it has been introduced in spar and then removed in the same PR, so it's gone from the code for now:
-- | Copied from galley's 'withTestService'
--
-- FUTUREWORK: use 'asyncWithBound' (that requires the test case to run in IO, though, or some
-- 'unliftIO' magic.)
--
-- The https server may take a few miliseconds (or, depending on your test setup, longer)
-- before it is available. To accomodate for this, the test will be run several times if it
-- throws an exception, and only after a few re-tries, the latest exception will be thrown.
withMockIdP
:: (HasCallStack)
=> (Chan e -> Application) -- ^ the mock service
-> (Chan e -> TestSpar a) -- ^ the test
-> TestSpar a
withMockIdP createApp go = do
config <- view teMockIdP
let tlss = Warp.tlsSettings (cert config) (privateKey config)
let defs = Warp.defaultSettings { Warp.settingsPort = botPort config }
buf <- liftIO newChan
srv <- liftIO . Async.async $
Warp.runTLS tlss defs $
createApp buf
patiently (reportIfServerDied srv >> go buf) `finally` liftIO (Async.cancel srv)
where
reportIfServerDied :: Async.Async () -> TestSpar ()
reportIfServerDied srv = liftIO (Async.poll srv >>= maybe (pure ()) print)
patiently :: TestSpar a -> TestSpar a
patiently = recovering policy continue . const
where
policy = limitRetries 3 <> exponentialBackoff 100000
continue = [\_ -> Control.Monad.Catch.Handler (\(SomeException _) -> pure True)]
Tasks:
- provide a variant of
withMockIdPfrom some library (bilge? wai-utilities?) - use that implementation instead of the ones listed above.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the duplicated server helpers in services/brig/test/integration/API/Provider.hs and services/galley/test/integration/API/Teams/LegalHold.hs, then run git grep -Hn runTLS to confirm the remaining instances. Compare the available bilge and wai-utilities locations with the shown withMockIdP variant. Done means a shared implementation replaces the listed helpers and the integration tests still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- testing
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100