wireapp / wireapp/wire-server

Reduce duplication of mock https servers in integration tests.

Open
#812 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue help wanted
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:

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 withMockIdP from 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.