Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra committed May 5, 2021
1 parent d9be407 commit b717faa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/Core/FileStore.hs
Expand Up @@ -19,7 +19,8 @@ module Development.IDE.Core.FileStore(
resetInterfaceStore,
getModificationTimeImpl,
addIdeGlobal,
getFileContentsImpl
getFileContentsImpl,
getModTime
) where

import Control.Concurrent.STM (atomically)
Expand All @@ -31,7 +32,6 @@ import Control.Monad.IO.Class
import qualified Data.ByteString as BS
import Data.Either.Extra
import qualified Data.HashMap.Strict as HM
import Data.Int (Int64)
import qualified Data.Map.Strict as Map
import Data.Maybe
import qualified Data.Rope.UTF16 as Rope
Expand Down
18 changes: 18 additions & 0 deletions ghcide/test/exe/Main.hs
Expand Up @@ -102,6 +102,9 @@ import Data.IORef.Extra (atomicModifyIORef_)
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
import Text.Regex.TDFA ((=~))
import qualified Progress
import Development.IDE.Core.FileStore (getModTime)
import Control.Concurrent (threadDelay)
import Text.Printf (printf)

waitForProgressBegin :: Session ()
waitForProgressBegin = skipManyTill anyMessage $ satisfyMaybe $ \case
Expand Down Expand Up @@ -5492,9 +5495,24 @@ unitTests = do
actualOrder <- liftIO $ readIORef orderRef

liftIO $ actualOrder @?= reverse [(1::Int)..20]
, testCase "timestamps have millisecond resolution" $ do
resolution_us <- findResolution_us 1
let msg = printf "Timestamps do not have millisecond resolution: %dus" resolution_us
assertBool msg (resolution_us <= 1000)
, Progress.tests
]

findResolution_us :: Int -> IO Int
findResolution_us delay_us | delay_us >= 1000000 = error "Unable to compute timestamp resolution"
findResolution_us delay_us = withTempFile $ \f -> withTempFile $ \f' -> do
writeFile f ""
threadDelay delay_us
writeFile f' ""
t <- getModTime f
t' <- getModTime f'
if t /= t' then return delay_us else findResolution_us (delay_us * 10)


testIde :: IDE.Arguments -> Session () -> IO ()
testIde arguments session = do
config <- getConfigFromEnv
Expand Down

0 comments on commit b717faa

Please sign in to comment.