Tests: drop TCL 8.6 dependency. (#7548)

This re-implements the redis-cli --pipe test so it no longer depends on a close feature available only in TCL 8.6.

Basically what this test does is run redis-cli --pipe, generates a bunch of commands and pipes them through redis-cli, and inspects the result in both Redis and the redis-cli output.

To do that, we need to close stdin for redis-cli to indicate we're done so it can flush its buffers and exit. TCL has bi-directional channels can only offers a way to "one-way close" a channel with TCL 8.6. To work around that, we now generate the commands into a file and feed that file to redis-cli directly.

As we're writing to an actual file, the number of commands is now reduced.
This commit is contained in:
Yossi Gottlieb 2020-07-21 14:17:14 +03:00 committed by GitHub
parent 343dd9bcce
commit f57e844b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,16 @@
source tests/support/cli.tcl
start_server {tags {"cli"}} {
proc open_cli {{opts "-n 9"}} {
proc open_cli {{opts "-n 9"} {infile ""}} {
set ::env(TERM) dumb
set cmdline [rediscli [srv port] $opts]
set fd [open "|$cmdline" "r+"]
if {$infile ne ""} {
set cmdline "$cmdline < $infile"
set mode "r"
} else {
set mode "r+"
}
set fd [open "|$cmdline" $mode]
fconfigure $fd -buffering none
fconfigure $fd -blocking false
fconfigure $fd -translation binary
@ -228,7 +234,7 @@ start_server {tags {"cli"}} {
assert_equal {} [r get should-not-exist]
}
test_nontty_cli "Dumping an RDB" {
test "Dumping an RDB" {
# Disk-based master
assert_match "OK" [r config set repl-diskless-sync no]
test_redis_cli_rdb_dump
@ -239,7 +245,7 @@ start_server {tags {"cli"}} {
test_redis_cli_rdb_dump
}
test_nontty_cli "Connecting as a replica" {
test "Connecting as a replica" {
set fd [open_cli "--replica"]
wait_for_condition 500 500 {
[string match {*slave0:*state=online*} [r info]]
@ -258,31 +264,30 @@ start_server {tags {"cli"}} {
close_cli $fd
}
test_nontty_cli "Piping raw protocol" {
set fd [open_cli "--pipe"]
fconfigure $fd -blocking true
test "Piping raw protocol" {
set cmds [tmpfile "cli_cmds"]
set cmds_fd [open $cmds "w"]
# Create a new deferring client and overwrite its fd
set client [redis [srv 0 "host"] [srv 0 "port"] 1 0]
set ::redis::fd($::redis::id) $fd
$client select 9
r del test-counter
for {set i 0} {$i < 10000} {incr i} {
$client incr test-counter
$client set large-key [string repeat "x" 20000]
}
puts $cmds_fd [formatCommand select 9]
puts $cmds_fd [formatCommand del test-counter]
for {set i 0} {$i < 1000} {incr i} {
$client set very-large-key [string repeat "x" 512000]
puts $cmds_fd [formatCommand incr test-counter]
puts $cmds_fd [formatCommand set large-key [string repeat "x" 20000]]
}
close $fd write
set output [read_cli $fd]
for {set i 0} {$i < 100} {incr i} {
puts $cmds_fd [formatCommand set very-large-key [string repeat "x" 512000]]
}
close $cmds_fd
assert_equal {10000} [r get test-counter]
assert_match {*All data transferred*errors: 0*replies: 21001*} $output
set cli_fd [open_cli "--pipe" $cmds]
fconfigure $cli_fd -blocking true
set output [read_cli $cli_fd]
close_cli $fd
assert_equal {1000} [r get test-counter]
assert_match {*All data transferred*errors: 0*replies: 2102*} $output
file delete $cmds
}
}