Skip to content

RedisCorpus ​

Rasuvaeff\PropertyTesting\Runner\RedisCorpus

Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2

Implements: Runner\Corpus, Runner\SearchCorpus

A Corpus in Redis, so one falsification is replayed everywhere.

Runner\FilesystemCorpus remembers a counterexample for whoever owns that directory — which, in CI, is a machine that is deleted when the job ends. The same corpus in Redis is shared: a failure found on a laptop replays in CI, a failure found in CI replays on the next laptop, and neither had to commit anything.

The document is byte-identical to the one on disk, so the two backends store the same artifact and moving between them is a copy rather than a migration.

php
$corpus = new RedisCorpus(new PhpRedisCorpusClient($redis));
(new PropertyRunner())->run($definition, $executor, corpus: $corpus);

Two differences from the filesystem backend are worth knowing before wiring it into a suite:

  • a shared corpus is a shared value space. A values entry is generator output, so anyone who can read the Redis instance can read the inputs that falsified a property. That is the same warning the directory carries, with a wider audience;
  • writes are optimistic, not locked. A write re-reads and retries when another writer got there first (Runner\MAX_ATTEMPTS times), then gives up silently. A corpus is memory, not a ledger: losing one entry to a storm of concurrent writers costs a replay, while throwing would fail a test run that had already passed.

Constants ​

ConstantTypeValueDescription
MAX_ATTEMPTSint5How many times a write re-reads and retries before giving up. Contention here is one property's key being written by two runs at the same moment; a handful of attempts covers that, and a number large enough to cover a pathological storm would only make the run slower without making the corpus more correct.

Constructor ​

php
__construct(
    \Runner\Redis\CorpusClient $client,
    string $prefix = 'property-testing:corpus:',
    int $maxValues = 8,
    int $maxSeeds = 2,
)
ParameterTypeDefaultDescription
$clientRunner\Redis\CorpusClientrequiredThe Redis client seam — Runner\Redis\PhpRedisCorpusClient for ext-redis, Runner\Redis\PredisCorpusClient for predis, or your own.
$prefixstring'property-testing:corpus:'Key prefix, so a corpus can share an instance with everything else that lives there. The key is this prefix plus the sha1 of the property id, exactly as the filesystem backend names its files.
$maxValuesint8How many values entries a property keeps, oldest evicted first. The default matches the filesystem backend; a shared corpus may reasonably keep more.
$maxSeedsint2How many seed entries a property keeps, oldest evicted first.

Methods ​

recall() ​

php
recall(string $id, list<string> $parameterNames): array

The usable entries recorded for the property, cheapest first. Entries that can no longer replay faithfully (foreign format, superseded sequence epoch, a signature that no longer matches) are skipped, not surfaced.

Documentation inherited from Runner\Corpus.

  • $id — The property id, as the runner knows it.
  • $parameterNames — The property's current parameters, in order.

remember() ​

php
remember(
    string $id,
    \CounterExample $counterExample,
    list<string> $parameterNames,
): void

Records a falsification's counterexample as the newest entry, preferring its minimised arguments over the bare seed.

Documentation inherited from Runner\Corpus.

  • $id — The property id, as the runner knows it.
  • $counterExample — The failure to record.
  • $parameterNames — The property's current parameters, in order.

prune() ​

php
prune(string $id, \Runner\CorpusEntry $entry): void

Drops an entry whose replay no longer fails — the regression is fixed and the entry has served its purpose.

Documentation inherited from Runner\Corpus.

  • $id — The property id, as the runner knows it.
  • $entry — The entry whose replay no longer fails.

Throws:

  • RuntimeException — When the entry cannot be re-encoded to the key that identifies it.

recallTargets() ​

php
recallTargets(string $id, list<string> $parameterNames): array

The search document of $id, from its own key beside the regression document's.

  • $id — The property id.
  • $parameterNames — The property method's current parameters, in order.

rememberTargets() ​

php
rememberTargets(
    string $id,
    \Runner\Targets $targets,
    list<string> $parameterNames,
): void

Replaces the search document of $id — the pool is the whole truth, so no compare-and-set is needed; an empty pool removes the key.

  • $id — The property id.
  • $targets — The pool, by label.
  • $parameterNames — The property method's current parameters, in order.