Skip to content

Commit 897adc1

Browse files
committed
Sentinel test files / directories layout improved.
The test now runs in a self-contained directory. The general abstractions to run the tests in an environment where mutliple instances are executed at the same time was extrapolated into instances.tcl, that will be reused to test Redis Cluster.
1 parent e6b6813 commit 897adc1

10 files changed

+38
-26
lines changed

runtest-sentinel

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ then
1111
echo "You need tcl 8.5 or newer in order to run the Redis Sentinel test"
1212
exit 1
1313
fi
14-
$TCLSH tests/sentinel.tcl $*
14+
$TCLSH tests/sentinel/run.tcl $*

tests/sentinel.tcl tests/instances.tcl

+15-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
# Sentinel test suite. Copyright (C) 2014 Salvatore Sanfilippo antirez@gmail.com
1+
# Multi-instance test framework.
2+
# This is used in order to test Sentinel and Redis Cluster, and provides
3+
# basic capabilities for spawning and handling N parallel Redis / Sentinel
4+
# instances.
5+
#
6+
# Copyright (C) 2014 Salvatore Sanfilippo antirez@gmail.com
27
# This softare is released under the BSD License. See the COPYING file for
38
# more information.
49

510
package require Tcl 8.5
611

712
set tcl_precision 17
8-
source tests/support/redis.tcl
9-
source tests/support/util.tcl
10-
source tests/support/server.tcl
11-
source tests/support/test.tcl
13+
source ../support/redis.tcl
14+
source ../support/util.tcl
15+
source ../support/server.tcl
16+
source ../support/test.tcl
1217

1318
set ::verbose 0
1419
set ::pause_on_error 0
@@ -22,8 +27,8 @@ set ::pids {} ; # We kill everything at exit
2227
set ::dirs {} ; # We remove all the temp dirs at exit
2328
set ::run_matching {} ; # If non empty, only tests matching pattern are run.
2429

25-
if {[catch {cd tests/sentinel-tmp}]} {
26-
puts "tests/sentinel-tmp directory not found."
30+
if {[catch {cd tmp}]} {
31+
puts "tmp directory not found."
2732
puts "Please run this test from the Redis source root."
2833
exit 1
2934
}
@@ -61,7 +66,7 @@ proc spawn_instance {type base_port count {conf {}}} {
6166
} else {
6267
error "Unknown instance type."
6368
}
64-
set pid [exec ../../src/${prgname} $cfgfile &]
69+
set pid [exec ../../../src/${prgname} $cfgfile &]
6570
lappend ::pids $pid
6671

6772
# Check availability
@@ -122,14 +127,6 @@ proc parse_options {} {
122127
}
123128
}
124129

125-
proc main {} {
126-
parse_options
127-
spawn_instance sentinel $::sentinel_base_port $::instances_count
128-
spawn_instance redis $::redis_base_port $::instances_count
129-
run_tests
130-
cleanup
131-
}
132-
133130
# If --pause-on-error option was passed at startup this function is called
134131
# on error in order to give the developer a chance to understand more about
135132
# the error condition while the instances are still running.
@@ -224,7 +221,7 @@ proc test {descr code} {
224221
}
225222

226223
proc run_tests {} {
227-
set tests [lsort [glob ../sentinel-tests/*]]
224+
set tests [lsort [glob ../tests/*]]
228225
foreach test $tests {
229226
if {$::run_matching ne {} && [string match $::run_matching $test] == 0} {
230227
continue
@@ -383,7 +380,7 @@ proc restart_instance {type id} {
383380
} else {
384381
set prgname redis-sentinel
385382
}
386-
set pid [exec ../../src/${prgname} $cfgfile &]
383+
set pid [exec ../../../src/${prgname} $cfgfile &]
387384
set_instance_attrib $type $id pid $pid
388385
lappend ::pids $pid
389386

@@ -396,7 +393,3 @@ proc restart_instance {type id} {
396393
set_instance_attrib $type $id link [redis 127.0.0.1 $port]
397394
}
398395

399-
if {[catch main e]} {
400-
puts $::errorInfo
401-
cleanup
402-
}

tests/sentinel/run.tcl

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Sentinel test suite. Copyright (C) 2014 Salvatore Sanfilippo antirez@gmail.com
2+
# This softare is released under the BSD License. See the COPYING file for
3+
# more information.
4+
5+
cd tests/sentinel
6+
source ../instances.tcl
7+
8+
proc main {} {
9+
parse_options
10+
spawn_instance sentinel $::sentinel_base_port $::instances_count
11+
spawn_instance redis $::redis_base_port $::instances_count
12+
run_tests
13+
cleanup
14+
}
15+
16+
if {[catch main e]} {
17+
puts $::errorInfo
18+
cleanup
19+
}

tests/sentinel-tests/00-base.tcl tests/sentinel/tests/00-base.tcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Check the basic monitoring and failover capabilities.
22

3-
source "../sentinel-tests/includes/init-tests.tcl"
3+
source "../tests/includes/init-tests.tcl"
44

55
if {$::simulate_error} {
66
test "This test will fail" {

tests/sentinel-tests/01-conf-update.tcl tests/sentinel/tests/01-conf-update.tcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Test Sentinel configuration consistency after partitions heal.
22

3-
source "../sentinel-tests/includes/init-tests.tcl"
3+
source "../tests/includes/init-tests.tcl"
44

55
test "We can failover with Sentinel 1 crashed" {
66
set old_port [RI $master_id tcp_port]

tests/sentinel-tests/02-slaves-reconf.tcl tests/sentinel/tests/02-slaves-reconf.tcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# 2) That partitioned slaves point to new master when they are partitioned
66
# away during failover and return at a latter time.
77

8-
source "../sentinel-tests/includes/init-tests.tcl"
8+
source "../tests/includes/init-tests.tcl"
99

1010
proc 03_test_slaves_replication {} {
1111
uplevel 1 {
File renamed without changes.

0 commit comments

Comments
 (0)