-- makes sure it matches up with an expected response.
-- The session directory should have a captured session file in it
-- named "session.log".
-replaySession :: FilePath -- ^ The recorded session directory.
+replaySession :: String -- ^ The command to run the server.
+ -> FilePath -- ^ The recorded session directory.
-> IO Bool
-replaySession sessionDir = do
+replaySession serverExe sessionDir = do
entries <- B.lines <$> B.readFile (sessionDir </> "session.log")
rspSema <- newEmptyMVar
passVar <- newEmptyMVar :: IO (MVar Bool)
- forkIO $ runSessionWithHandler (listenServer serverMsgs requestMap reqSema rspSema passVar) sessionDir $
- sendMessages clientMsgs reqSema rspSema
+ threadId <- forkIO $
+ runSessionWithHandler (listenServer serverMsgs requestMap reqSema rspSema passVar)
+ serverExe
+ sessionDir
+ (sendMessages clientMsgs reqSema rspSema)
- takeMVar passVar
+ result <- takeMVar passVar
+ killThread threadId
+ return result
where
isClientMsg (FromClient _ _) = True
print msg
putStrLn "Expected one of:"
mapM_ print $ takeWhile (not . isNotification) expectedMsgs
- print $ head $ dropWhile (not . isNotification) expectedMsgs
+ print $ head $ dropWhile isNotification expectedMsgs
putMVar passVar False
where