-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathrunQUIC.hs
More file actions
74 lines (68 loc) · 2.29 KB
/
runQUIC.hs
File metadata and controls
74 lines (68 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{-# LANGUAGE LambdaCase #-}
-- Run tests using the QUIC transport.
--
module Main where
import Control.Distributed.Process.Tests.CH (tests)
import Control.Exception (bracket, throwIO)
import Data.List.NonEmpty (NonEmpty (..))
import Network.Transport (Transport, closeTransport)
import Network.Transport.QUIC
( QUICTransportConfig (..),
createTransport,
credentialLoadX509,
)
import Network.Transport.Test (TestTransport (..))
import System.FilePath ((</>))
import System.IO
( BufferMode (LineBuffering),
hSetBuffering,
stderr,
stdout,
)
import Test.Tasty (defaultMain, localOption)
import Test.Tasty.Runners (NumThreads)
main :: IO ()
main = do
hSetBuffering stdout LineBuffering
hSetBuffering stderr LineBuffering
withQUICTransport $ \transport -> do
ts <-
tests
TestTransport
{ testTransport = transport,
testBreakConnection = \_ _ -> pure () -- I'm not sure how to break the connection at this time
}
-- Tests are time sensitive. Running the tests concurrently can slow them
-- down enough that threads using threadDelay would wake up later than
-- expected, thus changing the order in which messages were expected.
-- Therefore we run the tests sequentially
--
-- The problem was first detected with
-- 'Control.Distributed.Process.Tests.CH.testMergeChannels'
-- in particular.
defaultMain (localOption (1 :: NumThreads) ts)
withQUICTransport :: (Transport -> IO a) -> IO a
withQUICTransport =
bracket
(mkQUICTransport >>= either (throwIO . userError) pure)
closeTransport
mkQUICTransport :: IO (Either String Transport)
mkQUICTransport = do
credentialLoadX509
-- Generate a self-signed x509v3 certificate using this nifty tool:
-- https://certificatetools.com/
("tests" </> "credentials" </> "cert.crt")
("tests" </> "credentials" </> "cert.key")
>>= \case
Left errmsg -> pure $ Left errmsg
Right creds ->
Right
<$> createTransport
( QUICTransportConfig
{ hostName = "127.0.0.1",
serviceName = "0",
credentials = creds :| [],
-- credentials are self-signed, and therefore cannot be validated
validateCredentials = False
}
)