Skip to content

test(indexer): add integration test for indexer resume from checkpoint after restart - #690

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
omoh5:test/667-indexer-resume-from-checkpoint
Jul 28, 2026
Merged

test(indexer): add integration test for indexer resume from checkpoint after restart#690
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
omoh5:test/667-indexer-resume-from-checkpoint

Conversation

@omoh5

@omoh5 omoh5 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves #667 — adds an integration test that proves the indexer resumes from checkpoint.ledger + 1 after a simulated restart, and that no ledgers below the resume point are reprocessed.

The test (src/modules/indexer/indexer-resume.integration.test.ts) writes checkpoint records into the real ledgerCheckpoint table, calls getResumePoint() to simulate the indexer on-startup behaviour, and asserts both the resume-point value and the post-restart write boundary.

Acceptance Criteria Coverage

Criterion Test
Indexer resumes from ledger 5001 after checkpoint at 5000 writes a checkpoint for ledger 5000 and resumes from ledger 5001 after restart
No ledgers below 5001 are reprocessed after restart at checkpoint 5000, pre-existing activity rows are untouched and only events at ledgers ≥ 5001 are written
Resume ledger read from the checkpoint table, not hardcoded returns ledger + 1 for a checkpoint at non-5000 ledger (9999 → 10_000)
Test passes when the checkpoint table has multiple records (most recent is used) selects the highest ledger record and returns ledger + 1 (100, 2000, 5000 → resume 5001)

Design notes

  • Real Prisma DB throughout — mirrors the existing ledger-checkpoint.integration.test.ts pattern.
  • jest.spyOn (not jest.mock) scopes mocks to read-model operations processTradeEvents touches (activity, keyOwnership, creatorPriceSnapshot, indexedLedger). The real ledgerCheckpoint connection stays intact and is the unit under test.
  • processTradeEvents does not filter input events by ledger (the gating happens upstream, in the indexer polling loop). The test mirrors that contract explicitly in comments and feeds the function only events ≥ the resume point. The strongest contract assertion is the resume-point value itself (verified across 3 distinct ledger values).

Running locally

pnpm db:up                                                              # start docker compose postgres
pnpm exec prisma db push                                                # apply schema
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/accesslayer \\
  pnpm exec jest src/modules/indexer/indexer-resume.integration.test.ts

Expected: Tests: 5 passed, 5 total.

Testing

  • pnpm exec jest src/modules/indexer/indexer-resume.integration.test.ts — 5/5 tests pass locally against a Postgres test instance
  • pnpm exec tsc --noEmit — clean
  • pnpm lint — clean (test-only change, no production source touched)
  • pnpm build — N/A (test-only change)
  • pnpm exec prisma generate — no schema change

Checklist

…restart

Adds accesslayerorg#667 integration test covering the checkpoint-driven resume contract:

* Writes a checkpoint record for ledger 5000
* Reinitialises the indexer (simulates a restart) via getResumePoint()
* Asserts the indexer begins fetching from ledger 5001
* Asserts ledgers below 5001 are not reprocessed

Coverage:

* Primary scenario — checkpoint 5000 \u2192 resume 5001
* Most-recent-checkpoint is selected when multiple rows exist
* Resume ledger is sourced from the checkpoint table, not hardcoded
  (verified at ledger 9999 \u2192 10000 and on empty table \u2192 0)
* No ledgers below the resume point are reprocessed (pre-populated
  activity rows remain untouched; spy observes writes are at ledgers
  \u2265 resumeFrom; checkpoint table shape unchanged)

Mirrors the existing ledger-checkpoint.integration.test.ts pattern:
real Prisma DB + jest.spyOn for scoped read-model mocks only, so the
real ledger_checkpoint connection stays intact. processTradeEvents
extends prisma behind $extends; the mockImplementation on
prisma.activity.create is cast to any with an inline explanatory
note to satisfy the PrismaPromise return shape.

Refs accesslayerorg#667
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@omoh5 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093
Chucks1093 merged commit b81777d into accesslayerorg:main Jul 28, 2026
1 check passed
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.

Add integration test for indexer resuming from the correct ledger after a simulated restart

2 participants