Skip to content

Commit e22d757

Browse files
committed
Avoid duplicated instance execution code in Cluster test.
1 parent ca14440 commit e22d757

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

tests/instances.tcl

+21-26
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ if {[catch {cd tmp}]} {
3333
exit 1
3434
}
3535

36+
# Execute the specified instance of the server specified by 'type', using
37+
# the provided configuration file. Returns the PID of the process.
38+
proc exec_instance {type cfgfile} {
39+
if {$type eq "redis"} {
40+
set prgname redis-server
41+
} elseif {$type eq "sentinel"} {
42+
set prgname redis-sentinel
43+
} else {
44+
error "Unknown instance type."
45+
}
46+
47+
if {$::valgrind} {
48+
set pid [exec valgrind --track-origins=yes --suppressions=../../../src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full ../../../src/${prgname} $cfgfile &]
49+
} else {
50+
set pid [exec ../../../src/${prgname} $cfgfile &]
51+
}
52+
return $pid
53+
}
54+
3655
# Spawn a redis or sentinel instance, depending on 'type'.
3756
proc spawn_instance {type base_port count {conf {}}} {
3857
for {set j 0} {$j < $count} {incr j} {
@@ -59,20 +78,7 @@ proc spawn_instance {type base_port count {conf {}}} {
5978
close $cfg
6079

6180
# Finally exec it and remember the pid for later cleanup.
62-
if {$type eq "redis"} {
63-
set prgname redis-server
64-
} elseif {$type eq "sentinel"} {
65-
set prgname redis-sentinel
66-
} else {
67-
error "Unknown instance type."
68-
}
69-
70-
if {$::valgrind} {
71-
set pid [exec valgrind --track-origins=yes --suppressions=../../../src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full ../../../src/${prgname} $cfgfile &]
72-
} else {
73-
set pid [exec ../../../src/${prgname} $cfgfile &]
74-
}
75-
81+
set pid [exec_instance $type $cfgfile]
7682
lappend ::pids $pid
7783

7884
# Check availability
@@ -411,18 +417,7 @@ proc restart_instance {type id} {
411417

412418
# Execute the instance with its old setup and append the new pid
413419
# file for cleanup.
414-
if {$type eq "redis"} {
415-
set prgname redis-server
416-
} else {
417-
set prgname redis-sentinel
418-
}
419-
420-
if {$::valgrind} {
421-
set pid [exec valgrind --track-origins=yes --suppressions=../../../src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full ../../../src/${prgname} $cfgfile &]
422-
} else {
423-
set pid [exec ../../../src/${prgname} $cfgfile &]
424-
}
425-
420+
set pid [exec_instance $type $cfgfile]
426421
set_instance_attrib $type $id pid $pid
427422
lappend ::pids $pid
428423

0 commit comments

Comments
 (0)