mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
8a86bca5ed
This commit revives the improves the ability to run the test suite against external servers, instead of launching and managing `redis-server` processes as part of the test fixture. This capability existed in the past, using the `--host` and `--port` options. However, it was quite limited and mostly useful when running a specific tests. Attempting to run larger chunks of the test suite experienced many issues: * Many tests depend on being able to start and control `redis-server` themselves, and there's no clear distinction between external server compatible and other tests. * Cluster mode is not supported (resulting with `CROSSSLOT` errors). This PR cleans up many things and makes it possible to run the entire test suite against an external server. It also provides more fine grained controls to handle cases where the external server supports a subset of the Redis commands, limited number of databases, cluster mode, etc. The tests directory now contains a `README.md` file that describes how this works. This commit also includes additional cleanups and fixes: * Tests can now be tagged. * Tag-based selection is now unified across `start_server`, `tags` and `test`. * More information is provided about skipped or ignored tests. * Repeated patterns in tests have been extracted to common procedures, both at a global level and on a per-test file basis. * Cleaned up some cases where test setup was based on a previous test executing (a major anti-pattern that repeats itself in many places). * Cleaned up some cases where test teardown was not part of a test (in the future we should have dedicated teardown code that executes even when tests fail). * Fixed some tests that were flaky running on external servers.
93 lines
3.2 KiB
Tcl
93 lines
3.2 KiB
Tcl
start_server {tags {"repl external:skip"}} {
|
|
start_server {} {
|
|
test {First server should have role slave after SLAVEOF} {
|
|
r -1 slaveof [srv 0 host] [srv 0 port]
|
|
wait_for_condition 50 100 {
|
|
[s -1 master_link_status] eq {up}
|
|
} else {
|
|
fail "Replication not started."
|
|
}
|
|
}
|
|
|
|
test {If min-slaves-to-write is honored, write is accepted} {
|
|
r config set min-slaves-to-write 1
|
|
r config set min-slaves-max-lag 10
|
|
r set foo 12345
|
|
wait_for_condition 50 100 {
|
|
[r -1 get foo] eq {12345}
|
|
} else {
|
|
fail "Write did not reached replica"
|
|
}
|
|
}
|
|
|
|
test {No write if min-slaves-to-write is < attached slaves} {
|
|
r config set min-slaves-to-write 2
|
|
r config set min-slaves-max-lag 10
|
|
catch {r set foo 12345} err
|
|
set err
|
|
} {NOREPLICAS*}
|
|
|
|
test {If min-slaves-to-write is honored, write is accepted (again)} {
|
|
r config set min-slaves-to-write 1
|
|
r config set min-slaves-max-lag 10
|
|
r set foo 12345
|
|
wait_for_condition 50 100 {
|
|
[r -1 get foo] eq {12345}
|
|
} else {
|
|
fail "Write did not reached replica"
|
|
}
|
|
}
|
|
|
|
test {No write if min-slaves-max-lag is > of the slave lag} {
|
|
r config set min-slaves-to-write 1
|
|
r config set min-slaves-max-lag 2
|
|
exec kill -SIGSTOP [srv -1 pid]
|
|
assert {[r set foo 12345] eq {OK}}
|
|
wait_for_condition 100 100 {
|
|
[catch {r set foo 12345}] != 0
|
|
} else {
|
|
fail "Master didn't become readonly"
|
|
}
|
|
catch {r set foo 12345} err
|
|
assert_match {NOREPLICAS*} $err
|
|
}
|
|
exec kill -SIGCONT [srv -1 pid]
|
|
|
|
test {min-slaves-to-write is ignored by slaves} {
|
|
r config set min-slaves-to-write 1
|
|
r config set min-slaves-max-lag 10
|
|
r -1 config set min-slaves-to-write 1
|
|
r -1 config set min-slaves-max-lag 10
|
|
r set foo aaabbb
|
|
wait_for_condition 50 100 {
|
|
[r -1 get foo] eq {aaabbb}
|
|
} else {
|
|
fail "Write did not reached replica"
|
|
}
|
|
}
|
|
|
|
# Fix parameters for the next test to work
|
|
r config set min-slaves-to-write 0
|
|
r -1 config set min-slaves-to-write 0
|
|
r flushall
|
|
|
|
test {MASTER and SLAVE dataset should be identical after complex ops} {
|
|
createComplexDataset r 10000
|
|
after 500
|
|
if {[r debug digest] ne [r -1 debug digest]} {
|
|
set csv1 [csvdump r]
|
|
set csv2 [csvdump {r -1}]
|
|
set fd [open /tmp/repldump1.txt w]
|
|
puts -nonewline $fd $csv1
|
|
close $fd
|
|
set fd [open /tmp/repldump2.txt w]
|
|
puts -nonewline $fd $csv2
|
|
close $fd
|
|
puts "Master - Replica inconsistency"
|
|
puts "Run diff -u against /tmp/repldump*.txt for more info"
|
|
}
|
|
assert_equal [r debug digest] [r -1 debug digest]
|
|
}
|
|
}
|
|
}
|