@@ -13,7 +13,7 @@ import qualified Network.WebSockets as WS
13
13
import Network.Socket (withSocketsDo )
14
14
15
15
testServerConfig :: AppConfig
16
- testServerConfig = AppConfig
16
+ testServerConfig = AppConfig
17
17
{ configDatabase = " postgres://localhost/postgres"
18
18
, configPath = Nothing
19
19
, configHost = " *"
@@ -29,22 +29,22 @@ testServerConfig = AppConfig
29
29
startTestServer :: IO ThreadId
30
30
startTestServer = do
31
31
threadId <- forkIO $ serve testServerConfig
32
- threadDelay 1000
32
+ threadDelay 500000
33
33
pure threadId
34
34
35
35
withServer :: IO () -> IO ()
36
36
withServer action =
37
37
bracket startTestServer
38
- killThread
38
+ ( \ tid -> killThread tid >> threadDelay 500000 )
39
39
(const action)
40
40
41
41
sendWsData :: Text -> Text -> IO ()
42
42
sendWsData uri msg =
43
- withSocketsDo $
44
- WS. runClient
45
- " localhost"
46
- (configPort testServerConfig)
47
- (toS uri)
43
+ withSocketsDo $
44
+ WS. runClient
45
+ " localhost"
46
+ (configPort testServerConfig)
47
+ (toS uri)
48
48
(`WS.sendTextData` msg)
49
49
50
50
testChannel :: Text
@@ -60,27 +60,27 @@ waitForWsData :: Text -> IO (MVar ByteString)
60
60
waitForWsData uri = do
61
61
msg <- newEmptyMVar
62
62
void $ forkIO $
63
- withSocketsDo $
64
- WS. runClient
65
- " localhost"
66
- (configPort testServerConfig)
67
- (toS uri)
63
+ withSocketsDo $
64
+ WS. runClient
65
+ " localhost"
66
+ (configPort testServerConfig)
67
+ (toS uri)
68
68
(\ c -> do
69
69
m <- WS. receiveData c
70
70
putMVar msg m
71
71
)
72
- threadDelay 1000
72
+ threadDelay 10000
73
73
pure msg
74
74
75
75
waitForMultipleWsData :: Int -> Text -> IO (MVar [ByteString ])
76
76
waitForMultipleWsData messageCount uri = do
77
77
msg <- newEmptyMVar
78
78
void $ forkIO $
79
- withSocketsDo $
80
- WS. runClient
81
- " localhost"
82
- (configPort testServerConfig)
83
- (toS uri)
79
+ withSocketsDo $
80
+ WS. runClient
81
+ " localhost"
82
+ (configPort testServerConfig)
83
+ (toS uri)
84
84
(\ c -> do
85
85
m <- replicateM messageCount (WS. receiveData c)
86
86
putMVar msg m
@@ -114,6 +114,6 @@ spec = around_ withServer $
114
114
sendWsData testAndSecondaryChannel " test data"
115
115
msgsJson <- takeMVar msgs
116
116
117
- forM_
118
- msgsJson
117
+ forM_
118
+ msgsJson
119
119
(\ msgJson -> (msgJson ^? key " payload" . _String) `shouldBe` Just " test data" )
0 commit comments