From 650e5aa4c0cbf880e4ae15b5de4e6c9cb9f56f49 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 7 Sep 2012 00:59:50 +0900
Subject: [PATCH] Improve the prop_Alloc_sane test to detect mis-allocations

Currently, this just checks that a cluster cannot be rebalanced after
a single instance allocation. However, we can also test whether the
allocation decision computed a correct new cluster score, by checking
that against the one computed from the actual new node list.

Also, for nicer display, we convert the test from a Boolean to a
Property, with nice annotations.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 htest/Test/Ganeti/HTools/Cluster.hs | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/htest/Test/Ganeti/HTools/Cluster.hs b/htest/Test/Ganeti/HTools/Cluster.hs
index 60b771dae..f9b3a4655 100644
--- a/htest/Test/Ganeti/HTools/Cluster.hs
+++ b/htest/Test/Ganeti/HTools/Cluster.hs
@@ -134,14 +134,17 @@ prop_Alloc_sane inst =
       reqnodes = Instance.requiredNodes $ Instance.diskTemplate inst
   in case Cluster.genAllocNodes defGroupList nl reqnodes True >>=
      Cluster.tryAlloc nl il inst' of
-       Types.Bad _ -> False
+       Types.Bad msg -> failTest msg
        Types.Ok as ->
          case Cluster.asSolution as of
-           Nothing -> False
+           Nothing -> failTest "Failed to allocate, empty solution"
            Just (xnl, xi, _, cv) ->
              let il' = Container.add (Instance.idx xi) xi il
                  tbl = Cluster.Table xnl il' cv []
-             in not (canBalance tbl True True False)
+             in printTestCase "Cluster can be balanced after allocation"
+                  (not (canBalance tbl True True False)) .&&.
+                printTestCase "Solution score differs from actual node list:"
+                  (Cluster.compCV xnl ==? cv)
 
 -- | Checks that on a 2-5 node cluster, we can allocate a random
 -- instance spec via tiered allocation (whatever the original instance
-- 
GitLab