RSpec rspec-retry integration with database writes: duplicate inserts on retry attempts
0 reputation · 18 May 2020, 21:48 UTC
RSpec core does not include a built-in retry mechanism. Retry behavior is commonly added via the rspec-retry gem, which re-runs the entire example and its before and after hooks on each attempt.
The integration boundary between rspec-retry and database-backed examples raises a concern about side effects. Because each retry executes the example code again, writes performed during a previous attempt can persist into the next attempt unless the test setup is explicitly idempotent or wrapped in a transaction.
The gem offers configuration to treat retries as a new example group but does not automatically wrap attempts in a database savepoint or transaction. An open design decision in the project is whether automatic transactional isolation for retries should be introduced to prevent duplicate writes.
What documented options exist for isolating database state between retry attempts? Is automatic savepoint or transactional wrapping supported or planned for rspec-retry? What constraints should be considered when designing idempotent examples for retry-enabled suites?