Skip to content

test(valkey): add a contract suite for the Valkey fake - #6433

Merged
dan-petty merged 11 commits into
mainfrom
test/4557-valkey-contract-suite
Nov 19, 2026
Merged

dan-petty merged 11 commits into
mainfrom
test/4557-valkey-contract-suite

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The Valkey fake (fakeredis) refused EVAL and EVALSHA, so no valkey-py Lock or Lua script ran on it, and it had no contract suite. This change installs the lua extra 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.md forbids 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, ZADD trims, Lock, register_script, EVAL. ADR 0021 gets a Status History line.

The limits window case is not here, because limits is 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/

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.
@dan-petty dan-petty added type/test Type test: a new or changed test scope/valkey Valkey caches, queues and their keys labels Nov 19, 2026
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.
@dan-petty
dan-petty marked this pull request as ready for review November 19, 2026 16:04
@dan-petty
dan-petty merged commit 0057c41 into main Nov 19, 2026
32 checks passed
@dan-petty
dan-petty deleted the test/4557-valkey-contract-suite branch November 19, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/valkey Valkey caches, queues and their keys type/test Type test: a new or changed test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(valkey): add a contract suite for the Valkey fake

1 participant