Skip to content

Commit

Permalink
Reduce the probability of failure when start redis in runtest-cluster r…
Browse files Browse the repository at this point in the history
…edis#7554 (redis#7635)

When runtest-cluster, at first, we need to create a cluster use spawn_instance,
a port which is not used is choosen, however sometimes we can't run server on
the port. possibley due to a race with another process taking it first.
such as redis/redis/runs/896537490. It may be due to the machine problem or
In order to reduce the probability of failure when start redis in
runtest-cluster, we attemp to use another port when find server do not start up.

Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: yanhui13 <yanhui13@meituan.com>
  • Loading branch information
oranagra and fayadexinqing committed Aug 9, 2020
1 parent ca95b71 commit e2d6448
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions tests/instances.tcl
Expand Up @@ -59,8 +59,6 @@ proc exec_instance {type cfgfile} {
proc spawn_instance {type base_port count {conf {}}} {
for {set j 0} {$j < $count} {incr j} {
set port [find_available_port $base_port $::redis_port_count]
incr base_port
puts "Starting $type #$j at port $port"

# Create a directory for this instance.
set dirname "${type}_${j}"
Expand Down Expand Up @@ -93,10 +91,30 @@ proc spawn_instance {type base_port count {conf {}}} {
close $cfg

# Finally exec it and remember the pid for later cleanup.
set pid [exec_instance $type $cfgfile]
lappend ::pids $pid
set retry 100
while {$retry} {
set pid [exec_instance $type $cfgfile]

# Check availability
if {[server_is_up 127.0.0.1 $port 100] == 0} {
puts "Starting $type #$j at port $port failed, try another"
incr retry -1
set port [find_available_port $base_port $::redis_port_count]
set cfg [open $cfgfile a+]
if {$::tls} {
puts $cfg "tls-port $port"
} else {
puts $cfg "port $port"
}
close $cfg
} else {
puts "Starting $type #$j at port $port"
lappend ::pids $pid
break
}
}

# Check availability
# Check availability finally
if {[server_is_up 127.0.0.1 $port 100] == 0} {
abort_sentinel_test "Problems starting $type #$j: ping timeout"
}
Expand Down

0 comments on commit e2d6448

Please sign in to comment.