From cc455a710cc68d0fd8243cd1f04c5ee7332e4fdb Mon Sep 17 00:00:00 2001 From: Oran Agra Date: Mon, 31 Aug 2020 11:20:02 +0300 Subject: [PATCH] test infra - wait_done_loading reduce code duplication in aof.tcl. move creation of clients into the test so that it can be skipped --- tests/integration/aof.tcl | 44 +++++++-------------------------------- tests/support/util.tcl | 8 +++++++ 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/tests/integration/aof.tcl b/tests/integration/aof.tcl index b82c87d71..d81521374 100644 --- a/tests/integration/aof.tcl +++ b/tests/integration/aof.tcl @@ -52,15 +52,9 @@ tags {"aof"} { assert_equal 1 [is_alive $srv] } - set client [redis [dict get $srv host] [dict get $srv port] 0 $::tls] - - wait_for_condition 50 100 { - [catch {$client ping} e] == 0 - } else { - fail "Loading DB is taking too much time." - } - test "Truncated AOF loaded: we expect foo to be equal to 5" { + set client [redis [dict get $srv host] [dict get $srv port] 0 $::tls] + wait_done_loading $client assert {[$client get foo] eq "5"} } @@ -75,15 +69,9 @@ tags {"aof"} { assert_equal 1 [is_alive $srv] } - set client [redis [dict get $srv host] [dict get $srv port] 0 $::tls] - - wait_for_condition 50 100 { - [catch {$client ping} e] == 0 - } else { - fail "Loading DB is taking too much time." - } - test "Truncated AOF loaded: we expect foo to be equal to 6 now" { + set client [redis [dict get $srv host] [dict get $srv port] 0 $::tls] + wait_done_loading $client assert {[$client get foo] eq "6"} } } @@ -183,11 +171,7 @@ tags {"aof"} { test "Fixed AOF: Keyspace should contain values that were parseable" { set client [redis [dict get $srv host] [dict get $srv port] 0 $::tls] - wait_for_condition 50 100 { - [catch {$client ping} e] == 0 - } else { - fail "Loading DB is taking too much time." - } + wait_done_loading $client assert_equal "hello" [$client get foo] assert_equal "" [$client get bar] } @@ -207,11 +191,7 @@ tags {"aof"} { test "AOF+SPOP: Set should have 1 member" { set client [redis [dict get $srv host] [dict get $srv port] 0 $::tls] - wait_for_condition 50 100 { - [catch {$client ping} e] == 0 - } else { - fail "Loading DB is taking too much time." - } + wait_done_loading $client assert_equal 1 [$client scard set] } } @@ -231,11 +211,7 @@ tags {"aof"} { test "AOF+SPOP: Set should have 1 member" { set client [redis [dict get $srv host] [dict get $srv port] 0 $::tls] - wait_for_condition 50 100 { - [catch {$client ping} e] == 0 - } else { - fail "Loading DB is taking too much time." - } + wait_done_loading $client assert_equal 1 [$client scard set] } } @@ -254,11 +230,7 @@ tags {"aof"} { test "AOF+EXPIRE: List should be empty" { set client [redis [dict get $srv host] [dict get $srv port] 0 $::tls] - wait_for_condition 50 100 { - [catch {$client ping} e] == 0 - } else { - fail "Loading DB is taking too much time." - } + wait_done_loading $client assert_equal 0 [$client llen list] } } diff --git a/tests/support/util.tcl b/tests/support/util.tcl index bf590d402..021547854 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -99,6 +99,14 @@ proc wait_for_ofs_sync {r1 r2} { } } +proc wait_done_loading r { + wait_for_condition 50 100 { + [catch {$r ping} e] == 0 + } else { + fail "Loading DB is taking too much time." + } +} + # count current log lines in server's stdout proc count_log_lines {srv_idx} { set _ [exec wc -l < [srv $srv_idx stdout]]