From 50c302ca6faf5ce66b4823857889531b9803d197 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Fri, 30 Nov 2012 09:15:22 +0100 Subject: [PATCH] Create a genInstanceMaybeBiggerThan function This is used only once when testing Cluster.hs, but having it abstracted clarifies there what that call is about, makes that test shorter, and allows us to better do refactoring of the main genInstanceSmallerThan generator. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- htest/Test/Ganeti/HTools/Cluster.hs | 7 ++----- htest/Test/Ganeti/HTools/Instance.hs | 8 ++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/htest/Test/Ganeti/HTools/Cluster.hs b/htest/Test/Ganeti/HTools/Cluster.hs index 96bd1cf52..75525b438 100644 --- a/htest/Test/Ganeti/HTools/Cluster.hs +++ b/htest/Test/Ganeti/HTools/Cluster.hs @@ -37,7 +37,7 @@ import Test.Ganeti.TestHelper import Test.Ganeti.TestCommon import Test.Ganeti.TestHTools import Test.Ganeti.HTools.Instance ( genInstanceSmallerThanNode - , genInstanceSmallerThan ) + , genInstanceMaybeBiggerThanNode ) import Test.Ganeti.HTools.Node (genOnlineNode, genNode) import Ganeti.BasicTypes @@ -191,10 +191,7 @@ prop_CanTieredAlloc :: Property prop_CanTieredAlloc = forAll (choose (2, 5)) $ \count -> forAll (genOnlineNode `suchThat` isNodeBig 4) $ \node -> - forAll (genInstanceSmallerThan - (Node.availMem node + Types.unitMem * 2) - (Node.availDisk node + Types.unitDsk * 3) - (Node.availCpu node + Types.unitCpu * 4)) $ \inst -> + forAll (genInstanceMaybeBiggerThanNode node) $ \inst -> let nl = makeSmallCluster node count il = Container.empty rqnodes = Instance.requiredNodes $ Instance.diskTemplate inst diff --git a/htest/Test/Ganeti/HTools/Instance.hs b/htest/Test/Ganeti/HTools/Instance.hs index be6adc97f..59ef515fc 100644 --- a/htest/Test/Ganeti/HTools/Instance.hs +++ b/htest/Test/Ganeti/HTools/Instance.hs @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Test.Ganeti.HTools.Instance ( testHTools_Instance , genInstanceSmallerThanNode + , genInstanceMaybeBiggerThanNode , genInstanceSmallerThan , Instance.Instance(..) ) where @@ -66,6 +67,13 @@ genInstanceSmallerThanNode node = (Node.availDisk node `div` 2) (Node.availCpu node `div` 2) +-- | Generates an instance possibly bigger than a node. +genInstanceMaybeBiggerThanNode :: Node.Node -> Gen Instance.Instance +genInstanceMaybeBiggerThanNode node = + genInstanceSmallerThan (Node.availMem node + Types.unitMem * 2) + (Node.availDisk node + Types.unitDsk * 3) + (Node.availCpu node + Types.unitCpu * 4) + -- let's generate a random instance instance Arbitrary Instance.Instance where arbitrary = genInstanceSmallerThan maxMem maxDsk maxCpu -- GitLab