From c3f85c010738a9a84bf60d2b4c7654c5c6b76e92 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 24 Apr 2014 18:01:41 +0200 Subject: [PATCH] Redis Cluster test framework skeleton. --- runtest-cluster | 14 +++++++++++++ tests/cluster/cluster.tcl | 7 +++++++ tests/cluster/run.tcl | 22 +++++++++++++++++++++ tests/cluster/tests/00-base.tcl | 16 +++++++++++++++ tests/cluster/tests/includes/init-tests.tcl | 13 ++++++++++++ 5 files changed, 72 insertions(+) create mode 100755 runtest-cluster create mode 100644 tests/cluster/cluster.tcl create mode 100644 tests/cluster/run.tcl create mode 100644 tests/cluster/tests/00-base.tcl create mode 100644 tests/cluster/tests/includes/init-tests.tcl diff --git a/runtest-cluster b/runtest-cluster new file mode 100755 index 00000000..27829a5f --- /dev/null +++ b/runtest-cluster @@ -0,0 +1,14 @@ +#!/bin/sh +TCL_VERSIONS="8.5 8.6" +TCLSH="" + +for VERSION in $TCL_VERSIONS; do + TCL=`which tclsh$VERSION 2>/dev/null` && TCLSH=$TCL +done + +if [ -z $TCLSH ] +then + echo "You need tcl 8.5 or newer in order to run the Redis Sentinel test" + exit 1 +fi +$TCLSH tests/cluster/run.tcl $* diff --git a/tests/cluster/cluster.tcl b/tests/cluster/cluster.tcl new file mode 100644 index 00000000..685c501d --- /dev/null +++ b/tests/cluster/cluster.tcl @@ -0,0 +1,7 @@ +# Cluster-specific test functions. +# +# Copyright (C) 2014 Salvatore Sanfilippo antirez@gmail.com +# This softare is released under the BSD License. See the COPYING file for +# more information. + + diff --git a/tests/cluster/run.tcl b/tests/cluster/run.tcl new file mode 100644 index 00000000..acb6d49c --- /dev/null +++ b/tests/cluster/run.tcl @@ -0,0 +1,22 @@ +# Cluster test suite. Copyright (C) 2014 Salvatore Sanfilippo antirez@gmail.com +# This softare is released under the BSD License. See the COPYING file for +# more information. + +cd tests/cluster +source cluster.tcl +source ../instances.tcl + +proc main {} { + parse_options + spawn_instance redis $::redis_base_port $::instances_count { + "cluster-enabled yes" + "appendonly yes" + } + run_tests + cleanup +} + +if {[catch main e]} { + puts $::errorInfo + cleanup +} diff --git a/tests/cluster/tests/00-base.tcl b/tests/cluster/tests/00-base.tcl new file mode 100644 index 00000000..e3b88e3e --- /dev/null +++ b/tests/cluster/tests/00-base.tcl @@ -0,0 +1,16 @@ +# Check the basic monitoring and failover capabilities. + +source "../tests/includes/init-tests.tcl" + +if {$::simulate_error} { + test "This test will fail" { + fail "Simulated error" + } +} + +test "Cluster nodes are reachable." { + foreach_redis_id id { + # Every node should just know itself. + assert {[R $id ping] eq {PONG}} + } +} diff --git a/tests/cluster/tests/includes/init-tests.tcl b/tests/cluster/tests/includes/init-tests.tcl new file mode 100644 index 00000000..e3d5471d --- /dev/null +++ b/tests/cluster/tests/includes/init-tests.tcl @@ -0,0 +1,13 @@ +# Initialization tests -- most units will start including this. + +test "(init) Restart killed instances" { + foreach type {redis} { + foreach_${type}_id id { + if {[get_instance_attrib $type $id pid] == -1} { + puts -nonewline "$type/$id " + flush stdout + restart_instance $type $id + } + } + } +}