Skip to content

Commit 785ffe6

Browse files
authored
Prevent tests setting singledb from breaking other tests (#2056)
Some Tcl test suites set the global variable `::singledb`. If they don't restore the value afterwards, they can affect other test suites, which leads to problems that are hard to track down. This change introduces a test tag 'singledb' that has the same effect, but it is local to the scope of the tag (a tags block, start_server or a single test case). The tests should use the tag instead of setting the global. Additional change: Use ECHO instead of PING in `valkey_deferring_client` and `valkey_client` procs when singledb is set, to avoid failing when the server is loading. (SELECT and ECHO are allowed while loading, but not PING.) --------- Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
1 parent a2001a3 commit 785ffe6

13 files changed

+28
-64
lines changed

tests/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The following compatibility and capability tags are currently used:
103103
| `needs:reset` | Uses `RESET` to reset client connections. |
104104
| `needs:save` | Uses `SAVE` or `BGSAVE` to create an RDB file. |
105105
| `needs:other-server` | Requires `--other-server-path`. |
106+
| `singledb` | Test runs as if `--singledb` was given. |
106107

107108
When using an external server (`--host` and `--port`), filtering using the
108109
`external:skip` tags is done automatically.

tests/integration/aof.tcl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,7 @@ tags {"aof external:skip"} {
674674
}
675675
}
676676

677-
# make sure the test infra won't use SELECT
678-
set old_singledb $::singledb
679-
set ::singledb 1
680-
681-
tags {"aof cluster external:skip"} {
677+
tags {"aof cluster external:skip singledb"} {
682678
test {Test cluster slots / cluster shards in aof won't crash} {
683679
create_aof $aof_dirpath $aof_file {
684680
append_to_aof [formatCommand cluster slots]
@@ -735,5 +731,3 @@ tags {"aof cluster external:skip"} {
735731
clean_aof_persistence $aof_dirpath
736732
}
737733
}
738-
739-
set ::singledb $old_singledb

tests/support/server.tcl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ proc start_server {options {code undefined}} {
447447
set keep_persistence false
448448
set config_lines {}
449449
set start_other_server 0
450+
set old_singledb $::singledb
450451

451452
# Wait for the server to be ready and check for server liveness/client connectivity before starting the test.
452453
set wait_ready true
@@ -494,15 +495,22 @@ proc start_server {options {code undefined}} {
494495
if {![tags_acceptable $::tags err]} {
495496
incr ::num_aborted
496497
send_data_packet $::test_server_fd ignore $err
498+
set ::singledb $old_singledb
497499
set ::tags [lrange $::tags 0 end-[llength $tags]]
498500
return
499501
}
500502

503+
# Tags that override global options
504+
if {[lsearch $::tags singledb] >= 0} {
505+
set ::singledb 1
506+
}
507+
501508
# If we are running against an external server, we just push the
502509
# host/port pair in the stack the first time
503510
if {$::external} {
504511
run_external_server_test $code $overrides
505512

513+
set ::singledb $old_singledb
506514
set ::tags [lrange $::tags 0 end-[llength $tags]]
507515
return
508516
}
@@ -773,13 +781,15 @@ proc start_server {options {code undefined}} {
773781
# pop the server object
774782
set ::servers [lrange $::servers 0 end-1]
775783

784+
set ::singledb $old_singledb
776785
set ::tags [lrange $::tags 0 end-[llength $tags]]
777786
kill_server $srv
778787
if {!$keep_persistence} {
779788
clean_persistence $srv
780789
}
781790
set _ ""
782791
} else {
792+
set ::singledb $old_singledb
783793
set ::tags [lrange $::tags 0 end-[llength $tags]]
784794
set _ $srv
785795
}

tests/support/test.tcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,17 @@ proc test {name code {okpattern undefined} {tags {}}} {
210210
return
211211
}
212212

213+
set old_singledb $::singledb
213214
set tags [concat $::tags $tags]
214215
if {![tags_acceptable $tags err]} {
215216
incr ::num_aborted
216217
send_data_packet $::test_server_fd ignore "$name: $err"
217218
return
218219
}
219220

221+
if {[lsearch $tags singledb] >= 0} {
222+
set ::singledb 1
223+
}
220224
incr ::num_tests
221225
set details {}
222226
lappend details "$name in $::curfile"
@@ -300,5 +304,6 @@ proc test {name code {okpattern undefined} {tags {}}} {
300304
send_data_packet $::test_server_fd err "Detected a memory leak in test '$name': $output"
301305
}
302306
}
307+
set ::singledb $old_singledb
303308
set ::cur_test $prev_test
304309
}

tests/test_helper.tcl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ proc valkey_deferring_client {args} {
213213
$client read
214214
} else {
215215
# For timing/symmetry with the above select
216-
$client ping
216+
# that doesn't return error while loading.
217+
$client echo goodday
217218
$client read
218219
}
219220
return $client
@@ -232,7 +233,7 @@ proc valkey_client {args} {
232233
# select the right db and read the response (OK), or at least ping
233234
# the server if we're in a singledb mode.
234235
if {$::singledb} {
235-
$client ping
236+
$client echo hey
236237
} else {
237238
$client select 9
238239
}

tests/unit/cluster/base.tcl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Check the basic monitoring and failover capabilities.
22

3-
# make sure the test infra won't use SELECT
4-
set old_singledb $::singledb
5-
set ::singledb 1
6-
7-
tags {tls:skip external:skip cluster} {
3+
tags {tls:skip external:skip cluster singledb} {
84

95
set base_conf [list cluster-enabled yes]
106
start_multiple_servers 5 [list overrides $base_conf] {
@@ -122,5 +118,3 @@ test "CLUSTER SLAVES and CLUSTER REPLICAS with zero replicas" {
122118
} ;# stop servers
123119

124120
} ;# tags
125-
126-
set ::singledb $old_singledb

tests/unit/cluster/cli.tcl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
source tests/support/cli.tcl
44

5-
# make sure the test infra won't use SELECT
6-
set old_singledb $::singledb
7-
set ::singledb 1
8-
95
# cluster creation is complicated with TLS, and the current tests don't really need that coverage
10-
tags {tls:skip external:skip cluster} {
6+
tags {tls:skip external:skip cluster singledb} {
117

128
set base_conf [list cluster-enabled yes cluster-node-timeout 1000]
139
start_multiple_servers 3 [list overrides $base_conf] {
@@ -535,5 +531,3 @@ start_multiple_servers 3 [list overrides $base_conf] {
535531
}
536532

537533
}
538-
539-
set ::singledb $old_singledb

tests/unit/cluster/cluster-multiple-meets.tcl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# make sure the test infra won't use SELECT
2-
set old_singledb $::singledb
3-
set ::singledb 1
4-
5-
tags {tls:skip external:skip cluster} {
1+
tags {tls:skip external:skip cluster singledb} {
62
set base_conf [list cluster-enabled yes]
73
start_multiple_servers 2 [list overrides $base_conf] {
84
test "Cluster nodes are reachable" {
@@ -86,6 +82,3 @@ tags {tls:skip external:skip cluster} {
8682
}
8783
} ;# stop servers
8884
} ;# tags
89-
90-
set ::singledb $old_singledb
91-

tests/unit/cluster/cluster-reliable-meet.tcl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# make sure the test infra won't use SELECT
2-
set old_singledb $::singledb
3-
set ::singledb 1
4-
5-
tags {tls:skip external:skip cluster} {
1+
tags {tls:skip external:skip cluster singledb} {
62
set CLUSTER_PACKET_TYPE_PING 0
73
set CLUSTER_PACKET_TYPE_PONG 1
84
set CLUSTER_PACKET_TYPE_MEET 2
@@ -76,8 +72,6 @@ tags {tls:skip external:skip cluster} {
7672
} ;# stop servers
7773
} ;# tags
7874

79-
set ::singledb $old_singledb
80-
8175
proc cluster_get_first_node_in_handshake id {
8276
set nodes [get_cluster_nodes $id]
8377
foreach n $nodes {

tests/unit/cluster/cross-version-cluster.tcl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
#
33
# Use minimal.conf to make sure we don't use any configs not supported on the old version.
44

5-
# make sure the test infra won't use SELECT
6-
set old_singledb $::singledb
7-
set ::singledb 1
8-
9-
tags {external:skip needs:other-server cluster} {
5+
tags {external:skip needs:other-server cluster singledb} {
106
# To run this test use the `--other-server-path` parameter and pass in a compatible server path supporting
117
# SendClusterMessage module API.
128
#
@@ -32,5 +28,3 @@ tags {external:skip needs:other-server cluster} {
3228
}
3329
}
3430
}
35-
36-
set ::singledb $old_singledb

0 commit comments

Comments
 (0)