Unverified Commit efb6495a authored by Salvatore Sanfilippo's avatar Salvatore Sanfilippo Committed by GitHub
Browse files

Merge pull request #6236 from yossigo/poc/conns

Abstract Connections I/O API & TLS Support
parents b8e02f2b 8e29b0b2
source tests/support/cli.tcl
start_server {tags {"cli"}} { start_server {tags {"cli"}} {
proc open_cli {} { proc open_cli {} {
set ::env(TERM) dumb set ::env(TERM) dumb
set fd [open [format "|src/redis-cli -p %d -n 9" [srv port]] "r+"] set cmdline [rediscli [srv port] "-n 9"]
set fd [open "|$cmdline" "r+"]
fconfigure $fd -buffering none fconfigure $fd -buffering none
fconfigure $fd -blocking false fconfigure $fd -blocking false
fconfigure $fd -translation binary fconfigure $fd -translation binary
...@@ -54,8 +57,8 @@ start_server {tags {"cli"}} { ...@@ -54,8 +57,8 @@ start_server {tags {"cli"}} {
} }
proc _run_cli {opts args} { proc _run_cli {opts args} {
set cmd [format "src/redis-cli -p %d -n 9 $args" [srv port]] set cmd [rediscli [srv port] [list -n 9 {*}$args]]
foreach {key value} $opts { foreach {key value} $args {
if {$key eq "pipe"} { if {$key eq "pipe"} {
set cmd "sh -c \"$value | $cmd\"" set cmd "sh -c \"$value | $cmd\""
} }
......
This diff is collapsed.
...@@ -6,6 +6,7 @@ cd tests/sentinel ...@@ -6,6 +6,7 @@ cd tests/sentinel
source ../instances.tcl source ../instances.tcl
set ::instances_count 5 ; # How many instances we use at max. set ::instances_count 5 ; # How many instances we use at max.
set ::tlsdir "../../tls"
proc main {} { proc main {} {
parse_options parse_options
......
# Test conditions where an instance is considered to be down # Test conditions where an instance is considered to be down
source "../tests/includes/init-tests.tcl" source "../tests/includes/init-tests.tcl"
source "../../../tests/support/cli.tcl"
proc ensure_master_up {} { proc ensure_master_up {} {
wait_for_condition 1000 50 { wait_for_condition 1000 50 {
...@@ -28,7 +29,7 @@ test "Crash the majority of Sentinels to prevent failovers for this unit" { ...@@ -28,7 +29,7 @@ test "Crash the majority of Sentinels to prevent failovers for this unit" {
test "SDOWN is triggered by non-responding but not crashed instance" { test "SDOWN is triggered by non-responding but not crashed instance" {
lassign [S 4 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] host port lassign [S 4 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] host port
ensure_master_up ensure_master_up
exec ../../../src/redis-cli -h $host -p $port debug sleep 10 > /dev/null & exec ../../../src/redis-cli -h $host -p $port {*}[rediscli_tls_config "../../../tests"] debug sleep 10 > /dev/null &
ensure_master_down ensure_master_down
ensure_master_up ensure_master_up
} }
......
proc rediscli_tls_config {testsdir} {
set tlsdir [file join $testsdir tls]
set cert [file join $tlsdir redis.crt]
set key [file join $tlsdir redis.key]
set cacert [file join $tlsdir ca.crt]
if {$::tls} {
return [list --tls --cert $cert --key $key --cacert $cacert]
} else {
return {}
}
}
proc rediscli {port {opts {}}} {
set cmd [list src/redis-cli -p $port]
lappend cmd {*}[rediscli_tls_config "tests"]
lappend cmd {*}$opts
return $cmd
}
...@@ -62,7 +62,7 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} { ...@@ -62,7 +62,7 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
lassign [split $ip_port :] start_host start_port lassign [split $ip_port :] start_host start_port
if {[catch { if {[catch {
set r {} set r {}
set r [redis $start_host $start_port] set r [redis $start_host $start_port 0 $::tls]
set nodes_descr [$r cluster nodes] set nodes_descr [$r cluster nodes]
$r close $r close
} e]} { } e]} {
...@@ -107,7 +107,7 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} { ...@@ -107,7 +107,7 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
# Connect to the node # Connect to the node
set link {} set link {}
catch {set link [redis $host $port]} catch {set link [redis $host $port 0 $::tls]}
# Build this node description as an hash. # Build this node description as an hash.
set node [dict create \ set node [dict create \
......
...@@ -39,8 +39,18 @@ array set ::redis::callback {} ...@@ -39,8 +39,18 @@ array set ::redis::callback {}
array set ::redis::state {} ;# State in non-blocking reply reading array set ::redis::state {} ;# State in non-blocking reply reading
array set ::redis::statestack {} ;# Stack of states, for nested mbulks array set ::redis::statestack {} ;# Stack of states, for nested mbulks
proc redis {{server 127.0.0.1} {port 6379} {defer 0}} { proc redis {{server 127.0.0.1} {port 6379} {defer 0} {tls 0} {tlsoptions {}}} {
set fd [socket $server $port] if {$tls} {
package require tls
::tls::init \
-cafile "$::tlsdir/ca.crt" \
-certfile "$::tlsdir/redis.crt" \
-keyfile "$::tlsdir/redis.key" \
{*}$tlsoptions
set fd [::tls::socket $server $port]
} else {
set fd [socket $server $port]
}
fconfigure $fd -translation binary fconfigure $fd -translation binary
set id [incr ::redis::id] set id [incr ::redis::id]
set ::redis::fd($id) $fd set ::redis::fd($id) $fd
...@@ -48,6 +58,7 @@ proc redis {{server 127.0.0.1} {port 6379} {defer 0}} { ...@@ -48,6 +58,7 @@ proc redis {{server 127.0.0.1} {port 6379} {defer 0}} {
set ::redis::blocking($id) 1 set ::redis::blocking($id) 1
set ::redis::deferred($id) $defer set ::redis::deferred($id) $defer
set ::redis::reconnect($id) 0 set ::redis::reconnect($id) 0
set ::redis::tls $tls
::redis::redis_reset_state $id ::redis::redis_reset_state $id
interp alias {} ::redis::redisHandle$id {} ::redis::__dispatch__ $id interp alias {} ::redis::redisHandle$id {} ::redis::__dispatch__ $id
} }
...@@ -72,7 +83,11 @@ proc ::redis::__dispatch__raw__ {id method argv} { ...@@ -72,7 +83,11 @@ proc ::redis::__dispatch__raw__ {id method argv} {
# Reconnect the link if needed. # Reconnect the link if needed.
if {$fd eq {}} { if {$fd eq {}} {
lassign $::redis::addr($id) host port lassign $::redis::addr($id) host port
set ::redis::fd($id) [socket $host $port] if {$::redis::tls} {
set ::redis::fd($id) [::tls::socket $host $port]
} else {
set ::redis::fd($id) [socket $host $port]
}
fconfigure $::redis::fd($id) -translation binary fconfigure $::redis::fd($id) -translation binary
set fd $::redis::fd($id) set fd $::redis::fd($id)
} }
......
This diff is collapsed.
...@@ -395,7 +395,7 @@ proc colorstr {color str} { ...@@ -395,7 +395,7 @@ proc colorstr {color str} {
# of seconds to the specified Redis instance. # of seconds to the specified Redis instance.
proc start_write_load {host port seconds} { proc start_write_load {host port seconds} {
set tclsh [info nameofexecutable] set tclsh [info nameofexecutable]
exec $tclsh tests/helpers/gen_write_load.tcl $host $port $seconds & exec $tclsh tests/helpers/gen_write_load.tcl $host $port $seconds $::tls &
} }
# Stop a process generating write load executed with start_write_load. # Stop a process generating write load executed with start_write_load.
...@@ -423,7 +423,7 @@ proc lshuffle {list} { ...@@ -423,7 +423,7 @@ proc lshuffle {list} {
# of ops to the specified Redis instance. # of ops to the specified Redis instance.
proc start_bg_complex_data {host port db ops} { proc start_bg_complex_data {host port db ops} {
set tclsh [info nameofexecutable] set tclsh [info nameofexecutable]
exec $tclsh tests/helpers/bg_complex_data.tcl $host $port $db $ops & exec $tclsh tests/helpers/bg_complex_data.tcl $host $port $db $ops $::tls &
} }
# Stop a process generating write load executed with start_bg_complex_data. # Stop a process generating write load executed with start_bg_complex_data.
......
This diff is collapsed.
start_server {tags {"limits"} overrides {maxclients 10}} { start_server {tags {"limits"} overrides {maxclients 10}} {
if {$::tls} {
set expected_code "*I/O error*"
} else {
set expected_code "*ERR max*reached*"
}
test {Check if maxclients works refusing connections} { test {Check if maxclients works refusing connections} {
set c 0 set c 0
catch { catch {
...@@ -12,5 +17,5 @@ start_server {tags {"limits"} overrides {maxclients 10}} { ...@@ -12,5 +17,5 @@ start_server {tags {"limits"} overrides {maxclients 10}} {
} e } e
assert {$c > 8 && $c <= 10} assert {$c > 8 && $c <= 10}
set e set e
} {*ERR max*reached*} } $expected_code
} }
...@@ -166,7 +166,11 @@ start_server {tags {"other"}} { ...@@ -166,7 +166,11 @@ start_server {tags {"other"}} {
tags {protocol} { tags {protocol} {
test {PIPELINING stresser (also a regression for the old epoll bug)} { test {PIPELINING stresser (also a regression for the old epoll bug)} {
set fd2 [socket $::host $::port] if {$::tls} {
set fd2 [::tls::socket $::host $::port]
} else {
set fd2 [socket $::host $::port]
}
fconfigure $fd2 -encoding binary -translation binary fconfigure $fd2 -encoding binary -translation binary
puts -nonewline $fd2 "SELECT 9\r\n" puts -nonewline $fd2 "SELECT 9\r\n"
flush $fd2 flush $fd2
......
...@@ -72,7 +72,11 @@ start_server {tags {"protocol"}} { ...@@ -72,7 +72,11 @@ start_server {tags {"protocol"}} {
foreach seq [list "\x00" "*\x00" "$\x00"] { foreach seq [list "\x00" "*\x00" "$\x00"] {
incr c incr c
test "Protocol desync regression test #$c" { test "Protocol desync regression test #$c" {
set s [socket [srv 0 host] [srv 0 port]] if {$::tls} {
set s [::tls::socket [srv 0 host] [srv 0 port]]
} else {
set s [socket [srv 0 host] [srv 0 port]]
}
puts -nonewline $s $seq puts -nonewline $s $seq
set payload [string repeat A 1024]"\n" set payload [string repeat A 1024]"\n"
set test_start [clock seconds] set test_start [clock seconds]
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment