From 7b5ce1ffb1d730774f1d8e990fea38e9ab54a148 Mon Sep 17 00:00:00 2001
From: antirez <antirez@gmail.com>
Date: Tue, 29 Apr 2014 18:40:43 +0200
Subject: [PATCH] Cluster test: slots allocation.

---
 tests/cluster/cluster.tcl       | 19 +++++++++++++++++++
 tests/cluster/tests/00-base.tcl | 10 ++++++++++
 2 files changed, 29 insertions(+)

diff --git a/tests/cluster/cluster.tcl b/tests/cluster/cluster.tcl
index f85f96fd..824f3a80 100644
--- a/tests/cluster/cluster.tcl
+++ b/tests/cluster/cluster.tcl
@@ -42,3 +42,22 @@ proc get_myself id {
     return {}
 }
 
+# Return the value of the specified CLUSTER INFO field.
+proc CI {n field} {
+    get_info_field [R $n cluster info] $field
+}
+
+# Assuming nodes are reest, this function performs slots allocation.
+# Only the first 'n' nodes are used.
+proc cluster_allocate_slots {n} {
+    set slot 16383
+    while {$slot >= 0} {
+        # Allocate successive slots to random nodes.
+        set node [randomInt $n]
+        lappend slots_$node $slot
+        incr slot -1
+    }
+    for {set j 0} {$j < $n} {incr j} {
+        R $j cluster addslots {*}[set slots_${j}]
+    }
+}
diff --git a/tests/cluster/tests/00-base.tcl b/tests/cluster/tests/00-base.tcl
index 6eb81f89..4777414e 100644
--- a/tests/cluster/tests/00-base.tcl
+++ b/tests/cluster/tests/00-base.tcl
@@ -51,6 +51,16 @@ test "Check if nodes auto-discovery works" {
     }
 }
 
+test "Before slots allocation, all nodes report cluster failure" {
+    foreach_redis_id id {
+        assert {[CI $id cluster_state] eq {fail}}
+    }
+}
+
+test "It is possible to perform slot allocation" {
+    cluster_allocate_slots 5
+}
+
 test "After the join, every node gets a different config epoch" {
     set trynum 60
     while {[incr trynum -1] != 0} {