diff options
author | Ivan Kasatenko <sky.31338@gmail.com> | 2019-07-31 19:17:53 +0300 |
---|---|---|
committer | Ben Gamari <ben@well-typed.com> | 2019-08-01 13:49:50 -0400 |
commit | 986643cb3506f2eedce96bf2d2c03873f105fad5 (patch) | |
tree | 330561ab31136aa0741ee2e9937aac51d9bc9bb1 /testsuite/tests/lib | |
parent | 5e04841c4641e2249066614065053166657e3eb4 (diff) | |
download | haskell-986643cb3506f2eedce96bf2d2c03873f105fad5.tar.gz |
Fix T16916 CI failures (#16966)
1. Slightly increased the waiting time for the tested effect to be more
profound.
2. Introduced measuring of the actual time spent waiting and adjusing
CPU time by it to compensate for threadDelay waiting time
inconsistencies.
Diffstat (limited to 'testsuite/tests/lib')
-rw-r--r-- | testsuite/tests/lib/base/T16916.hs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/testsuite/tests/lib/base/T16916.hs b/testsuite/tests/lib/base/T16916.hs index a5dafa515b..6084c95572 100644 --- a/testsuite/tests/lib/base/T16916.hs +++ b/testsuite/tests/lib/base/T16916.hs @@ -2,6 +2,7 @@ module Main where import Control.Concurrent import Foreign.C +import GHC.Clock import GHC.Event import System.CPUTime import System.Posix.Types @@ -21,12 +22,15 @@ makeTestSocketFd = do callback :: FdKey -> Event -> IO () callback _ _ = return () -idleCpuUsage :: IO Integer +-- Idle CPU usage with 0 for 0% and 10^12 for 100% +idleCpuUsage :: IO Double idleCpuUsage = do + startTime <- getMonotonicTime startCPUTime <- getCPUTime - threadDelay 500000 + threadDelay 1000000 endCPUTime <- getCPUTime - return $ endCPUTime - startCPUTime + endTime <- getMonotonicTime + return $ fromIntegral (endCPUTime - startCPUTime) / (endTime - startTime) main :: IO () main = do @@ -42,4 +46,4 @@ main = do -- CPU consumption should roughly be the same when just idling vs -- when idling after the event been triggered - print $ (fromIntegral eventTriggeredUsage / fromIntegral noEventUsage) < 2.0 + print $ eventTriggeredUsage / noEventUsage < 2.0 |