Skip to content

Commit 29272f8

Browse files
committed
Retry code actions in Wingman test suite
Just trying to fix the flaky Windows CI
1 parent 19c8a47 commit 29272f8

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

plugins/hls-tactics-plugin/test/Utils.hs

+22-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE ScopedTypeVariables #-}
55
{-# LANGUAGE TypeOperators #-}
66
{-# LANGUAGE ViewPatterns #-}
7+
{-# LANGUAGE TypeApplications #-}
78

89
module Utils where
910

@@ -116,20 +117,27 @@ mkGoldenTest eq tc occ line col input =
116117
-- wait for the entire build to finish, so that Tactics code actions that
117118
-- use stale data will get uptodate stuff
118119
void waitForBuildQueue
119-
actions <- getCodeActions doc $ pointRange line col
120-
case find ((== Just (tacticTitle tc occ)) . codeActionTitle) actions of
121-
Just (InR CodeAction {_command = Just c}) -> do
122-
executeCommand c
123-
_resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit)
124-
edited <- documentContents doc
125-
let expected_name = input <.> "expected" <.> "hs"
126-
-- Write golden tests if they don't already exist
127-
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
128-
T.writeFile expected_name edited
129-
expected <- liftIO $ T.readFile expected_name
130-
liftIO $ edited `eq` expected
131-
_ -> error $ show actions
132-
120+
retryAction 4 $ do
121+
actions <- getCodeActions doc $ pointRange line col
122+
case find ((== Just (tacticTitle tc occ)) . codeActionTitle) actions of
123+
Just (InR CodeAction {_command = Just c}) -> do
124+
executeCommand c
125+
_resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit)
126+
edited <- documentContents doc
127+
let expected_name = input <.> "expected" <.> "hs"
128+
-- Write golden tests if they don't already exist
129+
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
130+
T.writeFile expected_name edited
131+
expected <- liftIO $ T.readFile expected_name
132+
liftIO $ E.try (edited `eq` expected)
133+
_ -> return $ Left $ E.toException $ E.ErrorCall $ show actions
134+
135+
retryAction :: Int -> Session (Either E.SomeException a) -> Session a
136+
retryAction n act = do
137+
res <- act
138+
case (n, res) of
139+
(_, Right x) -> return x
140+
(_, Left e) -> if n>1 then retryAction (n-1) act else E.throw e
133141

134142
mkCodeLensTest
135143
:: FilePath

0 commit comments

Comments
 (0)