From cb4f96657b1d50338d274ef0efea22ca8acf4588 Mon Sep 17 00:00:00 2001 From: "bodong.ybd" Date: Tue, 8 Sep 2020 10:45:03 +0800 Subject: [PATCH] Tests: Some fixes for macOS 1) cur_test: when restart_server, "no such variable" error occurs ./runtest --single integration/rdb test {client freed during loading} SET ::cur_test restart_server kill_server test "Check for memory leaks (pid $pid)" SET ::cur_test UNSET ::cur_test UNSET ::cur_test // This global variable has been unset. 2) `ps --ppid` not available on macOS platform, can be replaced with `pgrep -P pid`. (cherry picked from commit e90385e2232d41fd7c40dc239279f9837e7bdf57) --- tests/support/test.tcl | 1 - tests/support/util.tcl | 25 +++++++++++++++++++++++++ tests/unit/oom-score-adj.tcl | 11 +---------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/support/test.tcl b/tests/support/test.tcl index f5b4c8bef..54d323fa2 100644 --- a/tests/support/test.tcl +++ b/tests/support/test.tcl @@ -190,5 +190,4 @@ proc test {name code {okpattern undefined} {options undefined}} { send_data_packet $::test_server_fd err "Detected a memory leak in test '$name': $output" } } - unset ::cur_test } diff --git a/tests/support/util.tcl b/tests/support/util.tcl index ecf9f230f..b9a65358f 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -494,3 +494,28 @@ proc start_bg_complex_data {host port db ops} { proc stop_bg_complex_data {handle} { catch {exec /bin/kill -9 $handle} } + +proc populate {num prefix size} { + set rd [redis_deferring_client] + for {set j 0} {$j < $num} {incr j} { + $rd set $prefix$j [string repeat A $size] + } + for {set j 0} {$j < $num} {incr j} { + $rd read + } + $rd close +} + +proc get_child_pid {idx} { + set pid [srv $idx pid] + if {[string match {*Darwin*} [exec uname -a]]} { + set fd [open "|pgrep -P $pid" "r"] + set child_pid [string trim [lindex [split [read $fd] \n] 0]] + } else { + set fd [open "|ps --ppid $pid -o pid" "r"] + set child_pid [string trim [lindex [split [read $fd] \n] 1]] + } + close $fd + + return $child_pid +} diff --git a/tests/unit/oom-score-adj.tcl b/tests/unit/oom-score-adj.tcl index 993004602..8eb09a993 100644 --- a/tests/unit/oom-score-adj.tcl +++ b/tests/unit/oom-score-adj.tcl @@ -14,15 +14,6 @@ if {$system_name eq {linux}} { return $val } - proc get_child_pid {} { - set pid [srv 0 pid] - set fd [open "|ps --ppid $pid -o pid" "r"] - set child_pid [string trim [lindex [split [read $fd] \n] 1]] - close $fd - - return $child_pid - } - test {CONFIG SET oom-score-adj works as expected} { set base [get_oom_score_adj] @@ -47,7 +38,7 @@ if {$system_name eq {linux}} { r config set rdb-key-save-delay 100000 r bgsave - set child_pid [get_child_pid] + set child_pid [get_child_pid 0] assert {[get_oom_score_adj $child_pid] == [expr $base + 30]} }