Skip to content

Commit

Permalink
Cleanup integration tests (#839)
Browse files Browse the repository at this point in the history
* Remove unhelpful comment.

* Always recover working copy of config files in integration tests.
  • Loading branch information
fisx authored Sep 2, 2019
1 parent f826495 commit ef763f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
1 change: 0 additions & 1 deletion services/brig/brig.integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ zauth:
providerTokenTimeout: 60

turn:
# Replace this with the list of supported URIs
servers: test/resources/turn/servers.txt
serversV2: test/resources/turn/servers-v2.txt
# This should be the same secret as used by the TURN servers
Expand Down
40 changes: 24 additions & 16 deletions services/brig/test/integration/API/TURN.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@ import Data.List ((\\))
import Data.List1 (List1)
import Data.Misc (Port)
import Network.HTTP.Client (Manager)
import System.IO.Temp (writeTempFile)
import System.FilePath ((</>))
import Test.Tasty
import Test.Tasty.HUnit
import UnliftIO.Exception (finally)
import Util

import qualified Data.ByteString.Lazy as LB
import qualified Data.List1 as List1

type TurnUpdater = String -> IO ()
import qualified UnliftIO.Temporary as Temp

tests :: Manager -> Brig -> FilePath -> FilePath -> IO TestTree
tests m b turn turnV2 = do
return $ testGroup "turn"
[ test m "basic /calls/config - 200" $ resetTurn >> testCallsConfig b
[ test m "basic /calls/config - 200" $ testCallsConfig b
-- FIXME: requires tests to run on same host as brig
, test m "multiple servers /calls/config - 200" $ resetTurn >> testCallsConfigMultiple b (setTurn turn)
, test m "multiple servers /calls/config/v2 - 200" $ resetTurn >> testCallsConfigMultipleV2 b (setTurn turnV2)
, test m "multiple servers /calls/config - 200" . withTurnFile turn $ testCallsConfigMultiple b
, test m "multiple servers /calls/config/v2 - 200" . withTurnFile turnV2 $ testCallsConfigMultipleV2 b
]
where
resetTurn = liftIO $ setTurn turn "turn:127.0.0.1:3478" >> setTurn turnV2 "turn:localhost:3478"

testCallsConfig :: Brig -> Http ()
testCallsConfig b = do
Expand Down Expand Up @@ -165,14 +163,24 @@ toTurnURI s h p t = turnURI s ip p t
ip = fromMaybe (error "Failed to parse host address")
$ fromByteString h

setTurn :: FilePath -> String -> IO ()
setTurn cfgDest newConf = do
tmpDir <- getTemporaryDirectory
tmpPathFile <- writeTempFile tmpDir "-turn.tmp" newConf
copyFile tmpPathFile cfgDest

type TurnUpdater = String -> IO ()

withTurnFile :: FilePath -> (TurnUpdater -> Http ()) -> Http ()
withTurnFile cfgDest action = do
Temp.withSystemTempDirectory "wire.temp" $ \tempdir -> do
let backup = tempdir </> "backup"
copyFile cfgDest backup
action (setTurn tempdir cfgDest)
`finally` copyFile backup cfgDest

-- This essentially writes 'newConf' to 'cfgDest', but in a portable way that makes sure
-- brig's filewatch notices that the file has changed.
setTurn :: FilePath -> FilePath -> String -> IO ()
setTurn tmpDir cfgDest newConf = do
let tmpFile = tmpDir </> "file"
writeFile tmpFile newConf
copyFile tmpFile cfgDest
-- TODO: This must be higher than the value specified
-- in the watcher in Brig.App (currently, 0.5 seconds)
threadDelay 1000000
-- Note that this may leave temporary files behind in
-- case of some exceptions
removeFile tmpPathFile

0 comments on commit ef763f3

Please sign in to comment.