From 986643cb3506f2eedce96bf2d2c03873f105fad5 Mon Sep 17 00:00:00 2001 From: Ivan Kasatenko Date: Wed, 31 Jul 2019 19:17:53 +0300 Subject: 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. --- testsuite/tests/lib/base/T16916.hs | 12 ++++++++---- 1 file 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 -- cgit v1.2.1