@@ -51,11 +51,9 @@ import Development.IDE.Test (Cursor,
5151 flushMessages ,
5252 standardizeQuotes ,
5353 waitForAction ,
54- garbageCollectDirtyKeys ,
5554 getStoredKeys ,
5655 waitForTypecheck ,
57- getFilesOfInterest ,
58- waitForBuildQueue )
56+ getFilesOfInterest , waitForGC )
5957import Development.IDE.Test.Runfiles
6058import qualified Development.IDE.Types.Diagnostics as Diagnostics
6159import Development.IDE.Types.Location
@@ -5845,83 +5843,75 @@ unitTests = do
58455843
58465844garbageCollectionTests :: TestTree
58475845garbageCollectionTests = testGroup " garbage collection"
5848- [ testGroup " dirty keys" (sharedGCtests $ garbageCollectDirtyKeys CheckOnSaveAndClose )
5849- ]
5850- where
5851- sharedGCtests gc =
5846+ [ testGroup " dirty keys"
58525847 [ testSession' " are collected" $ \ dir -> do
58535848 liftIO $ writeFile (dir </> " hie.yaml" ) " cradle: {direct: {arguments: [A]}}"
5854- void $ generateGarbage " A" dir
5855- garbage <- gc 0
5849+ doc <- generateGarbage " A" dir
5850+ closeDoc doc
5851+ garbage <- waitForGC
58565852 liftIO $ assertBool " no garbage was found" $ not $ null garbage
58575853
58585854 , testSession' " are deleted from the state" $ \ dir -> do
58595855 liftIO $ writeFile (dir </> " hie.yaml" ) " cradle: {direct: {arguments: [A]}}"
5860- void $ generateGarbage " A" dir
5856+ docA <- generateGarbage " A" dir
58615857 keys0 <- getStoredKeys
5862- garbage <- gc 0
5858+ closeDoc docA
5859+ garbage <- waitForGC
58635860 liftIO $ assertBool " something is wrong with this test - no garbage found" $ not $ null garbage
58645861 keys1 <- getStoredKeys
58655862 liftIO $ assertBool " keys were not deleted from the state" (length keys1 < length keys0)
58665863
58675864 , testSession' " are not regenerated unless needed" $ \ dir -> do
58685865 liftIO $ writeFile (dir </> " hie.yaml" ) " cradle: {direct: {arguments: [A.hs, B.hs]}}"
5869- void $ generateGarbage " A" dir
5866+ docA <- generateGarbage " A" dir
5867+ _docB <- generateGarbage " B" dir
58705868
5871- reopenB <- generateGarbage " B" dir
58725869 -- garbage collect A keys
58735870 keysBeforeGC <- getStoredKeys
5874- garbage <- gc 2
5871+ closeDoc docA
5872+ garbage <- waitForGC
58755873 liftIO $ assertBool " something is wrong with this test - no garbage found" $ not $ null garbage
58765874 keysAfterGC <- getStoredKeys
5877- liftIO $ assertBool " something is wrong with this test - keys were not deleted from the state" (length keysAfterGC < length keysBeforeGC)
5878- ff <- getFilesOfInterest
5879- liftIO $ assertBool (" something is wrong with this test - files of interest is " <> show ff) (null ff)
5880-
5881- -- typecheck B again
5882- doc <- reopenB
5883- void $ waitForTypecheck doc
5875+ liftIO $ assertBool " something is wrong with this test - keys were not deleted from the state"
5876+ (length keysAfterGC < length keysBeforeGC)
58845877
5885- -- review the keys in store now to validate that A keys have not been regenerated
5886- keysB' <- getStoredKeys
5878+ -- re-typecheck B and check that the keys for A have not materialized back
5879+ _docB <- generateGarbage " B" dir
5880+ keysB <- getStoredKeys
58875881 let regeneratedKeys = Set. filter (not . isExpected) $
5888- Set. intersection (Set. fromList garbage) (Set. fromList keysB' )
5882+ Set. intersection (Set. fromList garbage) (Set. fromList keysB)
58895883 liftIO $ regeneratedKeys @?= mempty
58905884
58915885 , testSession' " regenerate successfully" $ \ dir -> do
58925886 liftIO $ writeFile (dir </> " hie.yaml" ) " cradle: {direct: {arguments: [A]}}"
5893- reopenA <- generateGarbage " A" dir
5894- garbage <- gc 0
5887+ docA <- generateGarbage " A" dir
5888+ closeDoc docA
5889+ garbage <- waitForGC
58955890 liftIO $ assertBool " no garbage was found" $ not $ null garbage
58965891 let edit = T. unlines
58975892 [ " module A where"
58985893 , " a :: Bool"
58995894 , " a = ()"
59005895 ]
5901- doc <- reopenA
5896+ doc <- generateGarbage " A " dir
59025897 changeDoc doc [TextDocumentContentChangeEvent Nothing Nothing edit]
59035898 builds <- waitForTypecheck doc
59045899 liftIO $ assertBool " it still builds" builds
59055900 expectCurrentDiagnostics doc [(DsError , (2 ,4 ), " Couldn't match expected type" )]
59065901 ]
5902+ ]
5903+ where
5904+ isExpected k = any (`T.isPrefixOf` k) [" GhcSessionIO" ]
59075905
5908- isExpected k = any (`isPrefixOf` k) [" GhcSessionIO" ]
5909-
5910- generateGarbage :: String -> FilePath -> Session (Session TextDocumentIdentifier )
5906+ generateGarbage :: String -> FilePath -> Session TextDocumentIdentifier
59115907 generateGarbage modName dir = do
59125908 let fp = modName <> " .hs"
59135909 body = printf " module %s where" modName
59145910 doc <- createDoc fp " haskell" (T. pack body)
59155911 liftIO $ writeFile (dir </> fp) body
59165912 builds <- waitForTypecheck doc
59175913 liftIO $ assertBool " something is wrong with this test" builds
5918- closeDoc doc
5919- waitForBuildQueue
5920- -- dirty the garbage
5921- sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
5922- List [FileEvent (filePathToUri $ dir </> modName <> " .hs" ) FcChanged ]
5923-
5924- return $ openDoc (modName <> " .hs" ) " haskell"
5914+ return doc
59255915
59265916findResolution_us :: Int -> IO Int
59275917findResolution_us delay_us | delay_us >= 1000000 = error " Unable to compute timestamp resolution"
0 commit comments