Skip to content

Fix flaky test #2835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ghcide/src/Development/IDE/Core/FileExists.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,6 @@ fromChange FcChanged = Nothing
-------------------------------------------------------------------------------------

-- | Returns True if the file exists
-- Note that a file is not considered to exist unless it is saved to disk.
-- In particular, VFS existence is not enough.
-- Consider the following example:
-- 1. The file @A.hs@ containing the line @import B@ is added to the files of interest
-- Since @B.hs@ is neither open nor exists, GetLocatedImports finds Nothing
-- 2. The editor creates a new buffer @B.hs@
-- Unless the editor also sends a @DidChangeWatchedFile@ event, ghcide will not pick it up
-- Most editors, e.g. VSCode, only send the event when the file is saved to disk.
getFileExists :: NormalizedFilePath -> Action Bool
getFileExists fp = use_ GetFileExists fp

Expand Down
31 changes: 25 additions & 6 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import System.Process.Extra (CreateProcess (cwd),
import Test.QuickCheck
-- import Test.QuickCheck.Instances ()
import Control.Concurrent.Async
import Control.Lens (to, (^.))
import Control.Lens (to, (^.), (.~))
import Control.Monad.Extra (whenJust)
import Data.Function ((&))
import Data.IORef
Expand Down Expand Up @@ -133,6 +133,7 @@ import Test.Tasty.Ingredients.Rerun
import Test.Tasty.QuickCheck
import Text.Printf (printf)
import Text.Regex.TDFA ((=~))
import Language.LSP.Types.Lens (workspace, didChangeWatchedFiles)

data Log
= LogGhcIde Ghcide.Log
Expand Down Expand Up @@ -421,9 +422,12 @@ diagnosticTests = testGroup "diagnostics"
let contentA = T.unlines [ "module ModuleA where" ]
_ <- createDoc "ModuleA.hs" "haskell" contentA
expectDiagnostics [("ModuleB.hs", [])]
, ignoreTestBecause "Flaky #2831" $ testSessionWait "add missing module (non workspace)" $ do
-- need to canonicalize in Mac Os
tmpDir <- liftIO $ canonicalizePath =<< getTemporaryDirectory
, testCase "add missing module (non workspace)" $
-- By default lsp-test sends FileWatched notifications for all files, which we don't want
-- as non workspace modules will not be watched by the LSP server.
-- To work around this, we tell lsp-test that our client doesn't have the
-- FileWatched capability, which is enough to disable the notifications
withTempDir $ \tmpDir -> runInDir'' lspTestCapsNoFileWatches tmpDir "." "." [] $ do
let contentB = T.unlines
[ "module ModuleB where"
, "import ModuleA ()"
Expand Down Expand Up @@ -6306,7 +6310,18 @@ withLongTimeout = bracket_ (setEnv "LSP_TIMEOUT" "120" True) (unsetEnv "LSP_TIME

-- | Takes a directory as well as relative paths to where we should launch the executable as well as the session root.
runInDir' :: FilePath -> FilePath -> FilePath -> [String] -> Session a -> IO a
runInDir' dir startExeIn startSessionIn extraOptions s = do
runInDir' = runInDir'' lspTestCaps

runInDir''
:: ClientCapabilities
-> FilePath
-> FilePath
-> FilePath
-> [String]
-> Session b
-> IO b
runInDir'' lspCaps dir startExeIn startSessionIn extraOptions s = do

ghcideExe <- locateGhcideExecutable
let startDir = dir </> startExeIn
let projDir = dir </> startSessionIn
Expand All @@ -6326,10 +6341,11 @@ runInDir' dir startExeIn startSessionIn extraOptions s = do
-- Only sets HOME if it wasn't already set.
setEnv "HOME" "/homeless-shelter" False
conf <- getConfigFromEnv
runSessionWithConfig conf cmd lspTestCaps projDir $ do
runSessionWithConfig conf cmd lspCaps projDir $ do
configureCheckProject False
s


getConfigFromEnv :: IO SessionConfig
getConfigFromEnv = do
logColor <- fromMaybe True <$> checkEnv "LSP_TEST_LOG_COLOR"
Expand All @@ -6347,6 +6363,9 @@ getConfigFromEnv = do
lspTestCaps :: ClientCapabilities
lspTestCaps = fullCaps { _window = Just $ WindowClientCapabilities (Just True) Nothing Nothing }

lspTestCapsNoFileWatches :: ClientCapabilities
lspTestCapsNoFileWatches = lspTestCaps & workspace . Lens._Just . didChangeWatchedFiles .~ Nothing

openTestDataDoc :: FilePath -> Session TextDocumentIdentifier
openTestDataDoc path = do
source <- liftIO $ readFileUtf8 $ "test/data" </> path
Expand Down