Skip to content

Commit fdbc974

Browse files
committed
fix hiedbretry ghcide tests
1 parent c842f78 commit fdbc974

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

ghcide/test/exe/HieDbRetry.hs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,27 @@ import Data.Tuple.Extra (dupe)
1010
import qualified Database.SQLite.Simple as SQLite
1111
import Development.IDE.Session (retryOnException,
1212
retryOnSqliteBusy)
13-
import Development.IDE.Types.Logger (Logger (Logger), Priority,
14-
noLogging)
13+
-- import Development.IDE.Types.Logger (Logger (Logger), Priority,
14+
-- noLogging)
15+
import Control.Monad.IO.Class (MonadIO (liftIO))
16+
import Development.IDE.Types.Logger (LogMessage (LogOther),
17+
LogOtherMessage (LogOtherMessage, payload, priority),
18+
Priority,
19+
Recorder (Recorder, logger, tracer),
20+
noopRecorder)
1521
import qualified System.Random as Random
1622
import Test.Tasty (TestTree, testGroup)
1723
import Test.Tasty.HUnit (assertFailure, testCase, (@?=))
1824

19-
makeLogger :: Var [(Priority, Text)] -> Logger
20-
makeLogger msgsVar = Logger $ \priority msg -> modifyVar msgsVar (\msgs -> pure ((priority, msg) : msgs, ()))
25+
makeLogger :: Var [(Priority, Text)] -> Recorder LogMessage
26+
makeLogger msgsVar = Recorder{ logger = logger, tracer = undefined }
27+
where
28+
logger (LogOther LogOtherMessage{priority, payload}) = liftIO $ modifyVar msgsVar (\msgs -> pure ((priority, payload) : msgs, ()))
2129

2230
rng :: Random.StdGen
2331
rng = Random.mkStdGen 0
2432

25-
retryOnSqliteBusyForTest :: Logger -> Int -> IO a -> IO a
33+
retryOnSqliteBusyForTest :: Recorder LogMessage -> Int -> IO a -> IO a
2634
retryOnSqliteBusyForTest logger maxRetryCount = retryOnException isErrorBusy logger 1 1 maxRetryCount rng
2735

2836
isErrorBusy :: SQLite.SQLError -> Maybe SQLite.SQLError
@@ -60,7 +68,7 @@ tests = testGroup "RetryHieDb"
6068
let expected = 1 :: Int
6169
let maxRetryCount = 0
6270

63-
actual <- retryOnSqliteBusyForTest noLogging maxRetryCount (pure expected)
71+
actual <- retryOnSqliteBusyForTest noopRecorder maxRetryCount (pure expected)
6472

6573
actual @?= expected
6674

@@ -69,7 +77,7 @@ tests = testGroup "RetryHieDb"
6977
let maxRetryCount = 3
7078
let incrementThenThrow = modifyVar countVar (\count -> pure (dupe (count + 1))) >> throwIO errorBusy
7179

72-
_ <- tryJust isErrorBusy (retryOnSqliteBusyForTest noLogging maxRetryCount incrementThenThrow)
80+
_ <- tryJust isErrorBusy (retryOnSqliteBusyForTest noopRecorder maxRetryCount incrementThenThrow)
7381

7482
withVar countVar $ \count ->
7583
count @?= maxRetryCount + 1
@@ -86,7 +94,7 @@ tests = testGroup "RetryHieDb"
8694
modifyVar countVar (\count -> pure (dupe (count + 1)))
8795

8896

89-
_ <- tryJust isErrorCall (retryOnSqliteBusyForTest noLogging maxRetryCount throwThenIncrement)
97+
_ <- tryJust isErrorCall (retryOnSqliteBusyForTest noopRecorder maxRetryCount throwThenIncrement)
9098

9199
withVar countVar $ \count ->
92100
count @?= 0
@@ -101,7 +109,7 @@ tests = testGroup "RetryHieDb"
101109
else
102110
modifyVar countVar (\count -> pure (dupe (count + 1)))
103111

104-
_ <- retryOnSqliteBusy noLogging rng incrementThenThrowThenIncrement
112+
_ <- retryOnSqliteBusy noopRecorder rng incrementThenThrowThenIncrement
105113

106114
withVar countVar $ \count ->
107115
count @?= 2

0 commit comments

Comments
 (0)