Fix integer overflow in Node unittest
authorIustin Pop <iustin@google.com>
Thu, 26 Jan 2012 18:41:13 +0000 (19:41 +0100)
committerIustin Pop <iustin@google.com>
Thu, 26 Jan 2012 18:45:19 +0000 (19:45 +0100)
When using a really random "extra cpus" variable, this can overflow
(especially on 32 bit) and thus the final value can be < 0, thus the
test will fail to fail.

It doesn't make sense to test with huge values, so let's just generate
a reasonable value.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

htools/Ganeti/HTools/QC.hs

index d423996..bdc430d 100644 (file)
@@ -966,7 +966,8 @@ prop_Node_addPriFD node inst =
           inst' = setInstanceSmallerThanNode node inst
           inst'' = inst' { Instance.dsk = Instance.dsk inst }
 
-prop_Node_addPriFC (Positive extra) =
+prop_Node_addPriFC =
+  forAll (choose (1, maxCpu)) $ \extra ->
   forAll genOnlineNode $ \node ->
   forAll (arbitrary `suchThat` Instance.instanceNotOffline) $ \inst ->
   let inst' = setInstanceSmallerThanNode node inst