@@ -103,6 +103,7 @@ import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
103
103
import Text.Regex.TDFA ((=~) )
104
104
import Development.IDE.Core.FileStore (getModTime )
105
105
import Control.Concurrent (threadDelay )
106
+ import Text.Printf (printf )
106
107
107
108
waitForProgressBegin :: Session ()
108
109
waitForProgressBegin = skipManyTill anyMessage $ satisfyMaybe $ \ case
@@ -5468,16 +5469,23 @@ unitTests = do
5468
5469
actualOrder <- liftIO $ readIORef orderRef
5469
5470
5470
5471
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 )
5479
5476
]
5480
5477
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
+
5481
5489
testIde :: IDE. Arguments -> Session () -> IO ()
5482
5490
testIde arguments session = do
5483
5491
config <- getConfigFromEnv
0 commit comments