Skip to content

Commit ecc89c0

Browse files
committed
Close input stream manually, add a lock
1 parent e2d93ef commit ecc89c0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

hls-test-utils/src/Test/Hls.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ where
2121

2222
import Control.Applicative.Combinators
2323
import Control.Concurrent.Async (async, cancel, wait)
24+
import Control.Concurrent.Extra
2425
import Control.Exception.Base
2526
import Control.Monad.IO.Class
2627
import Data.ByteString.Lazy (ByteString)
@@ -43,6 +44,7 @@ import Language.LSP.Types.Capabilities (ClientCapabilities)
4344
import System.Directory (getCurrentDirectory,
4445
setCurrentDirectory)
4546
import System.IO.Extra
47+
import System.IO.Unsafe (unsafePerformIO)
4648
import System.Process.Extra (createPipe)
4749
import System.Time.Extra
4850
import Test.Hls.Util
@@ -89,6 +91,11 @@ silenceStderr action = withTempFile $ \temp ->
8991
keepCurrentDirectory :: IO a -> IO a
9092
keepCurrentDirectory = bracket getCurrentDirectory setCurrentDirectory . const
9193

94+
{-# NOINLINE lock #-}
95+
-- | Never run in parallel
96+
lock :: Lock
97+
lock = unsafePerformIO newLock
98+
9299
-- | Host a server, and run a test session on it
93100
-- Note: cwd will be shifted into @root@ in @Session a@
94101
runSessionWithServer' ::
@@ -102,7 +109,7 @@ runSessionWithServer' ::
102109
FilePath ->
103110
Session a ->
104111
IO a
105-
runSessionWithServer' plugin conf sconf caps root s = keepCurrentDirectory $ do
112+
runSessionWithServer' plugin conf sconf caps root s = withLock lock $ keepCurrentDirectory $ do
106113
(inR, inW) <- createPipe
107114
(outR, outW) <- createPipe
108115
server <-
@@ -119,11 +126,12 @@ runSessionWithServer' plugin conf sconf caps root s = keepCurrentDirectory $ do
119126
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide.descriptors
120127
}
121128
x <- runSessionWithHandles inW outR sconf caps root s
129+
hClose inW
122130
timeout 3 (wait server) >>= \case
123131
Just () -> pure ()
124132
Nothing -> do
125133
putStrLn "Server does not exit in 3s, canceling the async task..."
126134
(t, _) <- duration $ cancel server
127135
putStrLn $ "Finishing canceling (took " <> showDuration t <> "s)"
128-
sleep 0.1
136+
sleep 0.2
129137
pure x

0 commit comments

Comments
 (0)