Skip to content

Commit 405635c

Browse files
committed
Don't use withAsync
1 parent 09ad056 commit 405635c

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

cabal.project

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ tests: true
1919

2020
package *
2121
ghc-options: -haddock
22-
23-
package haskell-language-server
24-
test-show-details: direct
25-
package ghcide
2622
test-show-details: direct
2723

2824
write-ghc-environment-files: never

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

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Test.Hls
1919
where
2020

2121
import Control.Applicative.Combinators
22-
import Control.Concurrent.Async (withAsync)
22+
import Control.Concurrent.Async (async, wait)
2323
import Control.Exception.Base
2424
import Control.Monad.IO.Class
2525
import Data.ByteString.Lazy (ByteString)
@@ -49,11 +49,10 @@ import Test.Tasty.ExpectedFailure
4949
import Test.Tasty.Golden
5050
import Test.Tasty.HUnit
5151
import Test.Tasty.Ingredients.Rerun
52-
import Test.Tasty.Runners
5352

54-
-- | Run 'defaultMainWithRerun' with -j1, and silence stderr
53+
-- | Run 'defaultMainWithRerun', and silence stderr
5554
defaultTestRunner :: TestTree -> IO ()
56-
defaultTestRunner = muteStderr . defaultMainWithRerun . adjustOption (const $ NumThreads 1)
55+
defaultTestRunner = silenceStderr . defaultMainWithRerun
5756

5857
gitDiff :: FilePath -> FilePath -> [String]
5958
gitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]
@@ -72,13 +71,17 @@ runSessionWithServerFormatter plugin formatter =
7271
def
7372
fullCaps
7473

75-
-- | Silence stderr, running an action
76-
muteStderr :: IO () -> IO ()
77-
muteStderr action = withTempFile $ \tmp ->
78-
bracket (openFile tmp AppendMode) hClose $ \h -> do
74+
-- | Run an action, with stderr silenced
75+
silenceStderr :: IO () -> IO ()
76+
silenceStderr action = withTempFile $ \temp ->
77+
bracket (openFile temp ReadWriteMode) hClose $ \h -> do
7978
old <- hDuplicate stderr
79+
buf <- hGetBuffering stderr
8080
h `hDuplicateTo'` stderr
81-
bracket_ action (hClose old) (old `hDuplicateTo'` stderr)
81+
bracket_
82+
action
83+
(hClose old)
84+
(old `hDuplicateTo'` stderr >> hSetBuffering stderr buf)
8285

8386
-- | Host a server, and run a test session on it
8487
-- Note: cwd will be shifted into @root@ in @Session a@
@@ -98,19 +101,22 @@ runSessionWithServer' plugin conf sconf caps root s = do
98101
(outR, outW) <- createPipe
99102
-- restore cwd after running the session; otherwise the path to test data will be invalid
100103
cwd <- getCurrentDirectory
101-
let server =
102-
Ghcide.defaultMain
103-
def
104-
{ argsHandleIn = pure inR,
105-
argsHandleOut = pure outW,
106-
argsDefaultHlsConfig = conf,
107-
argsIdeOptions = \config sessionLoader ->
108-
let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True}
109-
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2}},
110-
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide.descriptors
111-
}
112-
x <- withAsync server $ \_ ->
104+
server <-
105+
async $
106+
Ghcide.defaultMain
107+
def
108+
{ argsHandleIn = pure inR,
109+
argsHandleOut = pure outW,
110+
argsDefaultHlsConfig = conf,
111+
argsIdeOptions = \config sessionLoader ->
112+
let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True}
113+
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2}},
114+
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide.descriptors
115+
}
116+
117+
x <-
113118
runSessionWithHandles inW outR sconf caps root s
114119
`finally` setCurrentDirectory cwd
120+
wait server
115121
sleep 0.5
116122
pure x

0 commit comments

Comments
 (0)