Repository navigation
test(valkey): add a contract suite for the Valkey fake - #6433
Merged
Merged
Conversation
The suite replays a record of a real valkey-server. Pytest starts no server and skips no case, as docs/TESTING.md lines 75, 76, 78 and 87 require. The change is test-only, so it has no spec delta.
The suite runs each scenario of tests/support/valkey_scenarios.py over FakeValkey. Without the lua extra of fakeredis, the Lock and Lua scenarios fail: the fake does not know SCRIPT or EVAL.
fakeredis[lua,valkey]==2.40.0 installs lupa 2.8, so the Valkey fake answers SCRIPT, EVAL and EVALSHA. The Lock and Lua scenarios of the contract suite now pass over the fake. The protocol test of ValkeyClient expected EVAL to fail on the fake; it now reads the reply of the script.
Each scenario now also runs through a real valkey-py client over RecordedValkey. RecordedValkey serves the recorded replies of a real valkey-server in order on a loopback port that the test binds. A command that is not the next recorded one gets an error reply and stays in unexpected. The suite asserts the same result on both sides, an empty unexpected list and no remaining reply. It fails when the record is not of the locked valkey-py. The recorder runs each scenario through a proxy in front of an empty valkey-server on loopback. It refuses a server that holds a key. Its docstring gives two ways to get an empty server: the unpacked Debian package, or a new temporary Pod of the official image with a port-forward. The record comes from valkey/valkey:9.1.4-alpine and valkey-py 6.2.0, and holds no host data.
docs/TESTING.md and the docstring of tests/support/fakes/valkey.py said that the Valkey fake has no contract suite. They now name tests/valkey/test_valkey_contract.py, the record and the replay, and say that the fake runs Lua through the lua extra of fakeredis. The docs say that #4563 adds the moving window of limits to the suite. The Valkey paragraph named a FakeValkeyClient that does not exist. The root valkey fixture installs a ValkeyClient on the in-memory server, and the paragraph now says so.
…suite fakeredis reads time.time() for each expiry. A stalled worker between SET PX and PTTL made the bounded TTL fact of lock_lifecycle false on a loaded host. The clock fixture stops the wall clock, so the fake reads the same TTL on each host.
The protocol test no longer reads the error of EVAL. The failure test now checks VALKEY_COMMAND_ERROR and exit code 1 of a refused command.
valkey-server needs liblzf.so.1, which the devcontainer does not have. The route now downloads liblzf1 and sets LD_LIBRARY_PATH. The docstring also names the one reply that changes between two records.
The fake now runs EVAL with the lua extra and has a contract suite. Add the Status History line, and give task 3.4 a negative search that the verification reader accepts.
lock_lifecycle read PTTL, so each new record held another reply. TTL in whole seconds does not change with the time between two commands. Two new records from a new, empty server are now the same file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Valkey fake (fakeredis) refused
EVALandEVALSHA, so no valkey-pyLockor Lua script ran on it, and it had no contract suite. This change installs theluaextra of fakeredis (lupa, MIT) and adds the suite.The issue asked pytest to start a local
valkey-server, or to skip without one.docs/TESTING.mdforbids both: a test starts no program and does not skip on host state. So the suite follows the Docker engine suite. Each scenario runs over the fake and over valkey-py on a loopback replay of the replies that a real Valkey 9.1.4 sent:SET NX EX,SET EXAT,HINCRBY,ZADDtrims,Lock,register_script,EVAL. ADR 0021 gets a Status History line.The
limitswindow case is not here, becauselimitsis not a dependency. See #4563, which adds it and the case.The suite adds 0.8 s:
uv run pytest tests/valkey/test_valkey_contract.py -q -n0 -p no:randomly --durations=0.Closes #4557
Change:
openspec/changes/archive/2026-11-19-4557-valkey-contract-suite/