Skip to content

fix(testing): purge_expired, inject_fault(table=) and replayed transactions behave like DynamoDB - #132

Merged
kalaspuff merged 2 commits into
issues-stack/6-operation-metricsfrom
issues-stack/7-test-helpers
Oct 31, 2026
Merged

kalaspuff merged 2 commits into
issues-stack/6-operation-metricsfrom
issues-stack/7-test-helpers

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The three test-helper issues of #98, all in the in-memory DynamoDB:

  • testing.purge_expired() deleted items DynamoDB's TTL never deletes. DynamoDB says "To be considered for expiry and deletion, the TTL can't be more than five years in the past", so a TTL of 0 or of ten years ago is left alone. The purge now deletes items whose TTL lies within five years (of 365 days) before at. The Rust test that used expires = 1_000 and a Python test that used a TTL in 1970 encoded the wrong rule; they now check both sides of it.
  • inject_fault(table=...) only looked at the first table of a call. A fault for bbb never fired for a BatchWriteItem, BatchGetItem or transaction that also uses aaa, nor for SELECT * FROM bbb, since PartiQL calls passed no table. It stayed pending and fired on a later call. Also, unprocessed=True for aaa returned both tables' requests unprocessed. A fault now matches any table a call uses: batches, both kinds of transaction, and the tables PartiQL statements name. An unprocessed fault for a table returns only that table's requests unprocessed and writes or reads the others.
  • A replayed TransactWriteItems reported no consumed capacity. DynamoDB bills a replay with the same token as a transactional read of the items the first call wrote. dynoxide-rs, whose tests are captured against DynamoDB, charges 2 read units per 4 KB of the larger of each item's old and new image, in the replay's own ReturnConsumedCapacity mode. The backend now remembers those sizes with the token and reports that.

Verified with Rust tests of the memory backend (TTL bounds, faults for the second table of batches, transactions and PartiQL statements, partial unprocessed batch writes and reads, replay capacity), each failing without the fix, and the Python purge test. make check passes.

Fixes #98

Checklist

  • Tests cover the change (in-memory backend: these are its test helpers)
  • Docs updated (testing guide, configuration reference, testing docstrings, changelog)
  • make check passes locally (lint, types, clippy, consistency, tests)
  • Breaking change? No, but tests that purged items with TTLs in 1970 now keep them, as DynamoDB does

Worth confirming

  • Assumption: "five years" is 5 × 365 days. DynamoDB does not say how it counts them, so items right at the boundary may differ by a day or two.

fctl session


Note

Low risk. It only changes the in-memory test backend and the dynamoxy.testing helpers, not the AWS adapter or production paths, but tests that relied on old TTLs being purged or on faults matching only a call's first table can behave differently.

What it does. Makes three test helpers of the in-memory DynamoDB behave like the real service. purge_expired leaves items whose TTL is more than five years in the past, inject_fault(table=...) matches any table a call uses (batches, transactions and PartiQL statements) and an unprocessed fault returns only that table's requests unprocessed, and a replayed TransactWriteItems now reports consumed capacity as a transactional read of the items the first call wrote. Rust and Python tests, the testing guide, the docstrings and the changelog are updated.

Behavior change for tests. Tests that purge items with a TTL of 0 or one far in the past now keep those items, so they must use a recent TTL; "five years" is counted as 5 × 365 days, which may differ from DynamoDB by a day or two at the boundary.

fctl review's first look at 213972d · 10 files, +254 −84 · Review agent settings

…ctions behave like DynamoDB

purge_expired() deleted items whose TTL is more than five years in the
past, which DynamoDB never considers for expiry. inject_fault(table=...)
only matched the first table of a call (never PartiQL statements), and
unprocessed=True returned every table's requests unprocessed: a fault
now matches any table a call uses and leaves only its table's requests
unprocessed. A TransactWriteItems replayed with its token reported no
consumed capacity; it now reports the transactional read DynamoDB bills.

Fixes #98

Co-authored-by: Carl Oscar Aaro <[email protected]>
@fctl-review

This comment has been minimized.

Comment thread python/dynamoxy/testing.py Resolved
Comment thread python/dynamoxy/testing.py Resolved
@fctl-sh

fctl-sh Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Stack of 10 pull requests, merged in this order with "Squash and merge":

  1. fix(models): numbers of union fields render as stored, and literals of plain enum members write #126 fix(models): numbers of union fields render as stored, and literals of plain enum members write
  2. fix(client): calls keep their middleware chain and deliver all their events #127 fix(client): calls keep their middleware chain and deliver all their events
  3. fix(pydantic): use_enum_values, forward references, RootModel fields and data-taking factories work #128 fix(pydantic): use_enum_values, forward references, RootModel fields and data-taking factories work
  4. fix(unique)!: upserts that race with creates, unique floats written back, and collections refused #129 fix(unique)!: upserts that race with creates, unique floats written back, and collections refused
  5. fix(transactions): commit() no longer raises after the transaction was applied #130 fix(transactions): commit() no longer raises after the transaction was applied
  6. fix(telemetry): records and metrics count PartiQL writes, throttles of failed calls, batch retries and rows #131 fix(telemetry): records and metrics count PartiQL writes, throttles of failed calls, batch retries and rows
  7. fix(testing): purge_expired, inject_fault(table=) and replayed transactions behave like DynamoDB #132 fix(testing): purge_expired, inject_fault(table=) and replayed transactions behave like DynamoDB ← this pull request
  8. fix(memory): queries refuse empty key values and start keys outside the key condition, and index keys have size limits #133 fix(memory): queries refuse empty key values and start keys outside the key condition, and index keys have size limits
  9. fix(binding): conversions take any mapping and refuse invalid wire values, and unknown table statuses are not active #134 fix(binding): conversions take any mapping and refuse invalid wire values, and unknown table statuses are not active
  10. fix(memory): PartiQL and expressions follow DynamoDB's rules, and hand-written conditions get no redundant parentheses #135 fix(memory): PartiQL and expressions follow DynamoDB's rules, and hand-written conditions get no redundant parentheses

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.

Test helpers: purge_expired, inject_fault(table=) and replayed transactions

1 participant