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 2, 2021
1 parent 24d9ad4 commit 1d82903
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 @@ -101,6 +101,9 @@ import qualified Language.LSP.Types as LSP
import Data.IORef.Extra (atomicModifyIORef_)
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
import Text.Regex.TDFA ((=~))
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 @@ -5464,8 +5467,23 @@ 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)
]

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 1d82903

Please sign in to comment.