Skip to content

Store correctness contract test suite#212

Merged
milindsrivastava1997 merged 5 commits intomainfrom
211-store-correctness-contract-tests
Mar 20, 2026
Merged

Store correctness contract test suite#212
milindsrivastava1997 merged 5 commits intomainfrom
211-store-correctness-contract-tests

Conversation

@zzylol
Copy link
Copy Markdown
Contributor

@zzylol zzylol commented Mar 20, 2026

Summary

Adds a store_correctness_tests module that defines a contract test suite — a single run_contract_suite function called from two #[test] entry points — one for each LockStrategy. Any future Store implementation can be validated by calling run_contract_suite with its factory.

Coverage (33 sub-tests per strategy = 66 assertions total)

Empty-store edge cases

  • Range query on empty store returns empty map
  • Exact query on empty store returns None
  • Earliest timestamp on empty store returns empty map

Single insert

  • Range query within bounds returns the entry
  • Range query outside bounds returns empty
  • Exact query hit (matching start and end)
  • Exact query with wrong start returns None
  • Exact query with wrong end returns None

Batch inserts

  • Full-range query returns all inserted entries
  • Results are chronologically ordered (ascending by window start)

Partial-range filtering

  • Only windows overlapping the query range are returned

Aggregation-ID isolation

  • Querying one agg-ID does not return entries from another

Earliest-timestamp tracking

  • Minimum timestamp is tracked across multiple inserts
  • Each aggregation ID tracks its own minimum independently

Cleanup policies

  • CircularBuffer: evicts oldest windows when count exceeds threshold
  • CircularBuffer: newest windows are retained after eviction
  • ReadBased: evicts windows after the configured read-count threshold
  • ReadBased: windows below the threshold are retained

DeltaSetAggregator exclusion

  • DeltaSetAggregator-typed agg IDs bypass cleanup entirely, even when the circular-buffer policy would otherwise evict

Keyed (label-grouped) entries

  • Entries with a KeyByLabelValues key are grouped correctly in query results
  • Keyed and unkeyed entries for the same agg-ID coexist without interference
  • Multiple distinct keys in the same time window are returned under separate map entries

Clone fidelity (all 11 accumulator types)

Each test inserts an accumulator into the store, queries it back, calls clone_boxed_core(), and asserts serialize_to_json() output is identical:

Accumulator Test
SumAccumulator non-zero sum preserved
MinMaxAccumulator min/max values preserved
DatasketchesKLLAccumulator (k=200) sketch with 20 data points preserved
IncreaseAccumulator value preserved
MultipleSumAccumulator multi-key sums preserved
MultipleMinMaxAccumulator multi-key min/max preserved
SetAggregatorAccumulator set of label-value keys preserved
DeltaSetAggregatorAccumulator added/removed key sets preserved
CountMinSketchAccumulator initialised sketch preserved
CountMinSketchWithHeapAccumulator initialised sketch with heap preserved
HydraKllSketchAccumulator multi-shard sketch with data preserved

Concurrency

  • 8 threads inserting concurrently produce no data loss (all windows queryable)
  • Concurrent reads from multiple threads all return complete results

Test plan

  • cargo test -p query_engine_rust store_correctness — 2 tests pass (PerKey + Global), 66 sub-assertions each
  • cargo fmt --all — no formatting issues

🤖 Generated with Claude Code

Base automatically changed from 139-profile-existing-simple-store to main March 20, 2026 02:33
zzylol and others added 2 commits March 19, 2026 21:35
Defines a run_contract_suite() function that tests every observable
behaviour of a Store implementation:

  - Empty-store edge cases (range query, exact query, earliest timestamp)
  - Single insert: range query hit/miss, exact query hit/miss (wrong start,
    wrong end)
  - Batch insert: count correctness, chronological ordering guaranteed
  - Partial range filtering (windows outside query range excluded)
  - Aggregation-ID isolation (inserts into agg 1 not visible to agg 2)
  - Earliest-timestamp tracking: global minimum, per agg-ID
  - Cleanup — CircularBuffer: oldest window evicted, newest 8 retained
  - Cleanup — ReadBased: evicted after threshold reads, unread window kept
  - Concurrency: 8-thread concurrent inserts (no data loss),
    8-thread concurrent reads (each returns full result set)

Two test entry points exercise both existing implementations:
  contract_per_key  — LockStrategy::PerKey (reference)
  contract_global   — LockStrategy::Global

Adding a new Store implementation requires only a new #[test] function
that calls run_contract_suite() with the new factory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ltaSet exclusion

- Add SerializableToSink import so clone-fidelity tests compile on concrete types
- Clone fidelity tests for all 11 accumulator types: SumAccumulator,
  MinMaxAccumulator, DatasketchesKLLAccumulator, IncreaseAccumulator,
  MultipleSumAccumulator, MultipleMinMaxAccumulator, SetAggregatorAccumulator,
  DeltaSetAggregatorAccumulator, CountMinSketchAccumulator,
  CountMinSketchWithHeapAccumulator, HydraKllSketchAccumulator
- Three keyed-entry tests: grouping by key, coexistence of keyed/unkeyed, multiple keys per window
- DeltaSetAggregator cleanup exclusion test
- Concurrency tests: concurrent inserts (8 threads) and concurrent reads

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zzylol zzylol force-pushed the 211-store-correctness-contract-tests branch from 95a5de9 to cf25142 Compare March 20, 2026 02:35
zzylol and others added 3 commits March 19, 2026 21:39
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@milindsrivastava1997 milindsrivastava1997 merged commit d2f497c into main Mar 20, 2026
4 checks passed
@milindsrivastava1997 milindsrivastava1997 deleted the 211-store-correctness-contract-tests branch March 20, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants