Verified Commit 54c6ce7a authored by Camil Staps's avatar Camil Staps 🚀

Fix MemoryLeaks test

Previously, we measured the size of the entire IWorld to check if memory
usage increased. This gives flaky results, because it includes share
names. Share names in these examples include TaskIds, which are
incremented, so slowly the share names become bigger. Using
copy_to_string, strings are padded to 4 or 8 bytes, depending on the
platform (32-bit or 64-bit). Because the share names also include the
path, the tests could fail on some systems in some paths, but not on
others (although the tests were always more likely to fail on 32-bit
systems).

With this commit, we measure the size of the share *values* ignoring
their names. Because `Map` is fully strict, the fold does not alter
evaluation order and this is safe.
parent 7e942348
Pipeline #47851 passed with stages
in 9 minutes and 7 seconds
......@@ -9,7 +9,8 @@ import qualified Data.Map as Map
import Text
import Testing.TestEvents
import graph_copy
import iTasks, iTasks.Testing.Unit, iTasks.Internal.Task, iTasks.Internal.TaskIO
import iTasks, iTasks.Testing.Unit
import iTasks.Internal.IWorld, iTasks.Internal.Task, iTasks.Internal.TaskIO
Start world = runUnitTests tests world
......@@ -18,10 +19,10 @@ repetitions =: 1000
tests :: [UnitTest]
tests =:
[ memoryConsumptionOf "recursive step" getIWorldSize
, memoryConsumptionOf "local share" (withShared 3 \_ -> getIWorldSize)
, memoryConsumptionOf "parallel task" (viewInformation [] 3 ||- getIWorldSize)
, memoryConsumptionOf "shared interaction task" (withShared 3 \sds -> viewSharedInformation [] sds ||- getIWorldSize)
[ memoryConsumptionOf "recursive step" getSharesSize
, memoryConsumptionOf "local share" (withShared 3 \_ -> getSharesSize)
, memoryConsumptionOf "parallel task" (viewInformation [] 3 ||- getSharesSize)
, memoryConsumptionOf "shared interaction task" (withShared 3 \sds -> viewSharedInformation [] sds ||- getSharesSize)
]
memoryConsumptionOf :: !String !(Task Int) -> UnitTest
......@@ -53,8 +54,9 @@ where
CustomFailReason $
concat ["Memory consumption increased by ", toString $ endSize - initSize, " bytes."]
getIWorldSize :: Task Int
getIWorldSize = mkInstantTask \_ iworld
# iworldString = copy_to_string iworld
# (iworldSize, iworldString) = usize iworldString
-> (Ok iworldSize, fst $ copy_from_string iworldString)
getSharesSize :: Task Int
getSharesSize = mkInstantTask \_ iworld=:{memoryShares}
-> (Ok ('Map'.foldrNoKey ((+) o nodeSize) 0 memoryShares), iworld)
where
nodeSize :: !.a -> Int
nodeSize x = size (copy_to_string x)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment