Haxl/tests/ProfileTests.hs
Simon Marlow 9744e9e122 Fix profile test
Summary:
The value was too sensitive, it was different in the dbg way, and even
when running individual tests vs. all tests.

Reviewed By: codemiller

Differential Revision: D3310273

fbshipit-source-id: b15f81350f389888189409e7195486dc218f2573
2016-05-31 06:25:54 -07:00

45 lines
1.2 KiB
Haskell

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module ProfileTests where
import Haxl.Prelude
import Data.List
import Haxl.Core
import Test.HUnit
import Data.IORef
import qualified Data.HashMap.Strict as HashMap
import qualified Data.HashSet as HashSet
import TestUtils
mkProfilingEnv = do
env <- makeTestEnv
return env { flags = (flags env) { report = 4 } }
collectsdata :: Assertion
collectsdata = do
env <- mkProfilingEnv
_x <- runHaxl env $
withLabel "bar" $
withLabel "foo" $
if length (intersect ["a"::Text, "b"] ["c"]) > 1
then return 5
else return (4::Int)
profData <- readIORef (profRef env)
assertEqual "has data" 3 $ HashMap.size profData
assertBool "foo allocates" $
case profileAllocs <$> HashMap.lookup "foo" profData of
Just x -> x > 0
Nothing -> False
assertEqual "bar does not allocate" (Just 0) $
profileAllocs <$> HashMap.lookup "bar" profData
assertEqual "foo's parent" (Just ["bar"]) $
HashSet.toList . profileDeps <$> HashMap.lookup "foo" profData
tests = TestList
[ TestLabel "collectsdata" $ TestCase collectsdata
]