Skip to content

Commit 108ffbc

Browse files
committed
diagnostics
1 parent 1ce0d6c commit 108ffbc

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

ghcide/test/exe/Main.hs

+16-8
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
103103
import Text.Regex.TDFA ((=~))
104104
import Development.IDE.Core.FileStore (getModTime)
105105
import Control.Concurrent (threadDelay)
106+
import Text.Printf (printf)
106107

107108
waitForProgressBegin :: Session ()
108109
waitForProgressBegin = skipManyTill anyMessage $ satisfyMaybe $ \case
@@ -5468,16 +5469,23 @@ unitTests = do
54685469
actualOrder <- liftIO $ readIORef orderRef
54695470

54705471
liftIO $ actualOrder @?= reverse [(1::Int)..20]
5471-
, testCase "timestamps have subsecond resolution" $ do
5472-
let f = "/tmp/ghcide-timestamp-test"
5473-
writeFile f ""
5474-
t <- getModTime f
5475-
threadDelay 1000 -- 1ms
5476-
writeFile f ""
5477-
t' <- getModTime f
5478-
assertBool "Timestamps do not have subsecond resolution" (t /= t')
5472+
, testCase "timestamps have millisecond resolution" $ do
5473+
resolution_us <- findResolution_us 1
5474+
let msg = printf "Timestamps do not have millisecond resolution: %dus" resolution_us
5475+
assertBool msg (resolution_us <= 1000)
54795476
]
54805477

5478+
findResolution_us :: Int -> IO Int
5479+
findResolution_us delay_us | delay_us >= 1000000 = error "Unable to compute timestamp resolution"
5480+
findResolution_us delay_us = withTempFile $ \f -> withTempFile $ \f' -> do
5481+
writeFile f ""
5482+
threadDelay delay_us
5483+
writeFile f' ""
5484+
t <- getModTime f
5485+
t' <- getModTime f'
5486+
if t /= t' then return delay_us else findResolution_us (delay_us * 10)
5487+
5488+
54815489
testIde :: IDE.Arguments -> Session () -> IO ()
54825490
testIde arguments session = do
54835491
config <- getConfigFromEnv

0 commit comments

Comments
 (0)