@@ -29,7 +29,6 @@ import System.Info
2929import System.IO (Handle, hClose)
3030import System.IO.Temp
3131import System.Process (readProcessWithExitCode, CreateProcess(cwd), readCreateProcessWithExitCode, proc)
32−import System.Timeout
3332import Test.Hspec
3433import Test.HUnit.Base
3534
@@ -40,7 +39,7 @@ import Obelisk.Run (getConfigRoute)
4039data ObRunState
4140 = ObRunState_Init
4241 | ObRunState_Startup
43− | ObRunState_BackendStarted Text -- Port of backend
42+ | ObRunState_BackendStarted
4443 deriving (Eq, Show)
4544
4645doubleQuotes :: (IsString a, Semigroup a) => a -> a
@@ -223,12 +222,12 @@ testObRunInDir mdir httpManager = handle_sh (\case ExitSuccess -> pure (); e ->
223222 writefile "config/common/route" . uri =<< liftIO getFreePort -- Use a free port initially
224223 maybe id chdir mdir $ runHandle "ob" ["run"] $ \stdout -> do
225224 freePort <- liftIO getFreePort
226− (_, firstUri) <- handleObRunStdout httpManager stdout
225+ firstUri <- handleObRunStdout httpManager stdout
227226 let newUri = uri freePort
228227 when (firstUri == newUri) $ errorExit $
229228 "Startup URI (" <> firstUri <> ") is the same as test URI (" <> newUri <> ")"
230229 maybe id (\_ -> chdir "..") mdir $ alterRouteTo newUri stdout
231− (_, runningUri) <- handleObRunStdout httpManager stdout
230+ runningUri <- handleObRunStdout httpManager stdout
232231 if runningUri /= newUri
233232 then errorExit $ "Reloading failed: expected " <> newUri <> " but got " <> runningUri
234233 else exit 0
@@ -275,32 +274,28 @@ alterRouteTo uri stdout = do
275274 "Reloading failed: " <> T.pack (show t)
276275
277276-- | Handle stdout of `ob run`: check that the frontend and backend servers are started correctly
278−handleObRunStdout :: HTTP.Manager -> Handle -> Sh (Text, Text)
277+handleObRunStdout :: HTTP.Manager -> Handle -> Sh Text
279278handleObRunStdout httpManager stdout = flip fix ObRunState_Init $ \loop state -> do
280279 liftIO (T.hGetLine stdout) >>= \t -> case state of
281280 ObRunState_Init
282− | "Running test..." `T.isPrefixOf` t -> loop ObRunState_Startup
281+ | "Running test..." `T.isPrefixOf` t -> loop ObRunState_BackendStarted
283282 ObRunState_Startup
284283 | t == "backend stopped; make a change to your code to reload" -> loop ObRunState_Startup
285− | Just port <- "Backend running on port " `T.stripPrefix` t -> loop $ ObRunState_BackendStarted port
284+ -- | Just port <- "Backend running on port " `T.stripPrefix` t -> loop $ ObRunState_BackendStarted port
286285 | not (T.null t) -> errorExit $ "Startup: " <> t -- If theres any other output here, startup failed
287− ObRunState_BackendStarted port
286+ ObRunState_BackendStarted
288287 | Just uri <- "Frontend running on " `T.stripPrefix` t -> do
289− obRunCheck httpManager stdout port uri
290− pure (port, uri)
288+ obRunCheck httpManager stdout uri
289+ pure uri
291290 | not (T.null t) -> errorExit $ "Started: " <> t -- If theres any other output here, startup failed
292291 _ -> loop state
293292
294293-- | Make requests to frontend/backend servers to check they are working properly
295−obRunCheck :: HTTP.Manager -> Handle -> Text -> Text -> Sh ()
296−obRunCheck httpManager stdout backendPort frontendUri = do
294+obRunCheck :: HTTP.Manager -> Handle -> Text -> Sh ()
295+obRunCheck httpManager _stdout frontendUri = do
297296 let req uri = liftIO $ HTTP.parseRequest (T.unpack uri) >>= flip HTTP.httpLbs httpManager
298297 req frontendUri >>= \r -> when (HTTP.responseStatus r /= HTTP.ok200) $ errorExit $
299298 "Request to frontend server failed: " <> T.pack (show r)
300− void $ req $ "http://localhost:" <> backendPort
301− liftIO (timeout 1000000 $ T.hGetLine stdout) >>= \case
302− Just t | "127.0.0.1" `T.isPrefixOf` t -> pure () -- Backend request logged
303− x -> errorExit $ "Couldn't get backend request log: " <> T.pack (show x)
304299
305300getFreePort :: IO Socket.PortNumber
306301getFreePort = Socket.withSocketsDo $ do