Skip to content

Commit 8363e39

Browse files
committed
give more time for server to start and close between server specs. trying to make server tests less flaky
1 parent 29ef2cc commit 8363e39

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

test/ServerSpec.hs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import qualified Network.WebSockets as WS
1313
import Network.Socket (withSocketsDo)
1414

1515
testServerConfig :: AppConfig
16-
testServerConfig = AppConfig
16+
testServerConfig = AppConfig
1717
{ configDatabase = "postgres://localhost/postgres"
1818
, configPath = Nothing
1919
, configHost = "*"
@@ -29,22 +29,22 @@ testServerConfig = AppConfig
2929
startTestServer :: IO ThreadId
3030
startTestServer = do
3131
threadId <- forkIO $ serve testServerConfig
32-
threadDelay 1000
32+
threadDelay 500000
3333
pure threadId
3434

3535
withServer :: IO () -> IO ()
3636
withServer action =
3737
bracket startTestServer
38-
killThread
38+
(\tid -> killThread tid >> threadDelay 500000)
3939
(const action)
4040

4141
sendWsData :: Text -> Text -> IO ()
4242
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)
4848
(`WS.sendTextData` msg)
4949

5050
testChannel :: Text
@@ -60,27 +60,27 @@ waitForWsData :: Text -> IO (MVar ByteString)
6060
waitForWsData uri = do
6161
msg <- newEmptyMVar
6262
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)
6868
(\c -> do
6969
m <- WS.receiveData c
7070
putMVar msg m
7171
)
72-
threadDelay 1000
72+
threadDelay 10000
7373
pure msg
7474

7575
waitForMultipleWsData :: Int -> Text -> IO (MVar [ByteString])
7676
waitForMultipleWsData messageCount uri = do
7777
msg <- newEmptyMVar
7878
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)
8484
(\c -> do
8585
m <- replicateM messageCount (WS.receiveData c)
8686
putMVar msg m
@@ -114,6 +114,6 @@ spec = around_ withServer $
114114
sendWsData testAndSecondaryChannel "test data"
115115
msgsJson <- takeMVar msgs
116116

117-
forM_
118-
msgsJson
117+
forM_
118+
msgsJson
119119
(\msgJson -> (msgJson ^? key "payload" . _String) `shouldBe` Just "test data")

0 commit comments

Comments
 (0)