Tests: Some fixes for macOS (#7757)

* 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`.

* handle cur_test for nested tests

if there are nested tests and nested servers, we need to restore the
previous value of cur_test when a test exist.

example:
```
test{test 1} {
	start_server {
		test{test 1.1 - master only} {
		}
		start_server {
		    test{test 1.2 - with replication} {
            }
		}
	}
}
```
when `test 1.1 - master only exists`, we're still inside `test 1`

Co-authored-by: Oran Agra <oran@redislabs.com>
This commit is contained in:
Oran Agra 2020-09-08 16:28:58 +03:00 committed by GitHub
commit 340963b2d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -4,6 +4,7 @@ set ::num_failed 0
set ::num_skipped 0
set ::num_aborted 0
set ::tests_failed {}
set ::cur_test ""
proc fail {msg} {
error "assertion:$msg"
@ -136,6 +137,7 @@ proc test {name code {okpattern undefined} {options undefined}} {
# set a cur_test global to be logged into new servers that are spown
# and log the test name in all existing servers
set prev_test $::cur_test
set ::cur_test "$name in $::curfile"
if {!$::external} {
foreach srv $::servers {
@ -190,5 +192,5 @@ 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
set ::cur_test $prev_test
}

View File

@ -508,8 +508,13 @@ proc populate {num prefix size} {
proc get_child_pid {idx} {
set pid [srv $idx pid]
set fd [open "|ps --ppid $pid -o pid" "r"]
set child_pid [string trim [lindex [split [read $fd] \n] 1]]
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