Skip to content

Commit

Permalink
Retry code actions in Wingman test suite
Browse files Browse the repository at this point in the history
Just trying to fix the flaky Windows CI
  • Loading branch information
pepeiborra committed Oct 2, 2021
1 parent 19c8a47 commit 29272f8
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions plugins/hls-tactics-plugin/test/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TypeApplications #-}

module Utils where

Expand Down Expand Up @@ -116,20 +117,27 @@ mkGoldenTest eq tc occ line col input =
-- wait for the entire build to finish, so that Tactics code actions that
-- use stale data will get uptodate stuff
void waitForBuildQueue
actions <- getCodeActions doc $ pointRange line col
case find ((== Just (tacticTitle tc occ)) . codeActionTitle) actions of
Just (InR CodeAction {_command = Just c}) -> do
executeCommand c
_resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit)
edited <- documentContents doc
let expected_name = input <.> "expected" <.> "hs"
-- Write golden tests if they don't already exist
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
T.writeFile expected_name edited
expected <- liftIO $ T.readFile expected_name
liftIO $ edited `eq` expected
_ -> error $ show actions

retryAction 4 $ do
actions <- getCodeActions doc $ pointRange line col
case find ((== Just (tacticTitle tc occ)) . codeActionTitle) actions of
Just (InR CodeAction {_command = Just c}) -> do
executeCommand c
_resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit)
edited <- documentContents doc
let expected_name = input <.> "expected" <.> "hs"
-- Write golden tests if they don't already exist
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
T.writeFile expected_name edited
expected <- liftIO $ T.readFile expected_name
liftIO $ E.try (edited `eq` expected)
_ -> return $ Left $ E.toException $ E.ErrorCall $ show actions

retryAction :: Int -> Session (Either E.SomeException a) -> Session a
retryAction n act = do
res <- act
case (n, res) of
(_, Right x) -> return x
(_, Left e) -> if n>1 then retryAction (n-1) act else E.throw e

mkCodeLensTest
:: FilePath
Expand Down

0 comments on commit 29272f8

Please # to comment.