21
21
22
22
import Control.Applicative.Combinators
23
23
import Control.Concurrent.Async (async , cancel , wait )
24
+ import Control.Concurrent.Extra
24
25
import Control.Exception.Base
25
26
import Control.Monad.IO.Class
26
27
import Data.ByteString.Lazy (ByteString )
@@ -43,6 +44,7 @@ import Language.LSP.Types.Capabilities (ClientCapabilities)
43
44
import System.Directory (getCurrentDirectory ,
44
45
setCurrentDirectory )
45
46
import System.IO.Extra
47
+ import System.IO.Unsafe (unsafePerformIO )
46
48
import System.Process.Extra (createPipe )
47
49
import System.Time.Extra
48
50
import Test.Hls.Util
@@ -89,6 +91,11 @@ silenceStderr action = withTempFile $ \temp ->
89
91
keepCurrentDirectory :: IO a -> IO a
90
92
keepCurrentDirectory = bracket getCurrentDirectory setCurrentDirectory . const
91
93
94
+ {-# NOINLINE lock #-}
95
+ -- | Never run in parallel
96
+ lock :: Lock
97
+ lock = unsafePerformIO newLock
98
+
92
99
-- | Host a server, and run a test session on it
93
100
-- Note: cwd will be shifted into @root@ in @Session a@
94
101
runSessionWithServer' ::
@@ -102,7 +109,7 @@ runSessionWithServer' ::
102
109
FilePath ->
103
110
Session a ->
104
111
IO a
105
- runSessionWithServer' plugin conf sconf caps root s = keepCurrentDirectory $ do
112
+ runSessionWithServer' plugin conf sconf caps root s = withLock lock $ keepCurrentDirectory $ do
106
113
(inR, inW) <- createPipe
107
114
(outR, outW) <- createPipe
108
115
server <-
@@ -119,11 +126,12 @@ runSessionWithServer' plugin conf sconf caps root s = keepCurrentDirectory $ do
119
126
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide. descriptors
120
127
}
121
128
x <- runSessionWithHandles inW outR sconf caps root s
129
+ hClose inW
122
130
timeout 3 (wait server) >>= \ case
123
131
Just () -> pure ()
124
132
Nothing -> do
125
133
putStrLn " Server does not exit in 3s, canceling the async task..."
126
134
(t, _) <- duration $ cancel server
127
135
putStrLn $ " Finishing canceling (took " <> showDuration t <> " s)"
128
- sleep 0.1
136
+ sleep 0.2
129
137
pure x
0 commit comments