Skip to content

Commit a57fa49

Browse files
committed
fix test
1 parent 1a03884 commit a57fa49

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import Test.Tasty.ExpectedFailure (expectFailBecause,
7777
ignoreTestBecause)
7878
import Test.Tasty.HUnit (Assertion, assertFailure,
7979
(@?=))
80+
import Language.LSP.Test (withTimeout)
8081

8182
noLiteralCaps :: ClientCapabilities
8283
noLiteralCaps = def & L.textDocument ?~ textDocumentCaps
@@ -284,25 +285,13 @@ expectNoMoreDiagnostics timeout doc src = do
284285
-- If timeout is 0 it will wait until the session timeout
285286
waitForDiagnosticsFromSourceWithTimeout :: Seconds -> TextDocumentIdentifier -> String -> Test.Session [Diagnostic]
286287
waitForDiagnosticsFromSourceWithTimeout timeout document source = do
287-
diags <- withTimeout timeout $ waitForDiagnosticsFrom document
288+
-- todo possible better if there is withTimeout on Seconds in LSP.
289+
diags <- withTimeout (ceiling timeout) $ waitForDiagnosticsFrom document
288290
return $ filter matches diags
289291
where
290292
matches :: Diagnostic -> Bool
291293
matches d = d ^. L.source == Just (T.pack source)
292294

293-
withTimeout :: Seconds -> Session a -> Session a
294-
withTimeout duration f = do
295-
chan <- asks messageChan
296-
timeoutId <- getCurTimeoutId
297-
modify $ \s -> s { overridingTimeout = True }
298-
tid <- liftIO $ forkIO $ do
299-
threadDelay (ceiling $ duration * 1000000)
300-
writeChan chan (TimeoutMessage timeoutId)
301-
res <- f
302-
liftIO $ killThread tid
303-
bumpTimeoutId timeoutId
304-
modify $ \s -> s { overridingTimeout = False }
305-
return res
306295

307296

308297
failIfSessionTimeout :: IO a -> IO a

0 commit comments

Comments
 (0)