summaryrefslogtreecommitdiff
path: root/tests/instances.tcl
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-01-21 16:46:51 +0100
committerantirez <antirez@gmail.com>2015-01-21 16:47:36 +0100
commitacb1d8debf23f3dbd9199d1276a86ada71750196 (patch)
tree82353953818244d03b52ab3b342b2b41cae93063 /tests/instances.tcl
parentb3bf7584b0aa5c2dbc1acf4d7f6b2c3d420e8e42 (diff)
downloadredis-acb1d8debf23f3dbd9199d1276a86ada71750196.tar.gz
Cluster test: wait for port to unbound in kill_instance.
Otherwise kill_instance + restart_instance in short succession will still find the port busy and will fail.
Diffstat (limited to 'tests/instances.tcl')
-rw-r--r--tests/instances.tcl16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/instances.tcl b/tests/instances.tcl
index a68b79d11..7d87cdf59 100644
--- a/tests/instances.tcl
+++ b/tests/instances.tcl
@@ -370,15 +370,31 @@ proc get_instance_id_by_port {type port} {
# The instance can be restarted with restart-instance.
proc kill_instance {type id} {
set pid [get_instance_attrib $type $id pid]
+ set port [get_instance_attrib $type $id port]
+
if {$pid == -1} {
error "You tried to kill $type $id twice."
}
+
exec kill -9 $pid
set_instance_attrib $type $id pid -1
set_instance_attrib $type $id link you_tried_to_talk_with_killed_instance
# Remove the PID from the list of pids to kill at exit.
set ::pids [lsearch -all -inline -not -exact $::pids $pid]
+
+ # Wait for the port it was using to be available again, so that's not
+ # an issue to start a new server ASAP with the same port.
+ set retry 10
+ while {[incr retry -1]} {
+ set port_is_free [catch {set s [socket 127.0.01 $port]}]
+ if {$port_is_free} break
+ catch {close $s}
+ after 1000
+ }
+ if {$retry == 0} {
+ error "Port $port does not return available after killing instance."
+ }
}
# Return true of the instance of the specified type/id is killed.