Guide

How to test pagination while records change

The PainHunt Team· Published · 5 min read

TL;DR: Test a paginated reader against a declared ordering and coverage contract, then change the dataset between pages. Check repeated and missing identities separately. A successful final HTTP response, a cursor and a deduplicated result are not, by themselves, proof of a complete export.

Define what complete means for this reader

A list screen, a one-time export and an incremental synchronizer may need different behavior. A screen can tolerate a refreshed view. A migration may require a fixed population. A synchronizer may deliberately revisit an overlap window and reconcile changes.

Write down the population, filters, ordering, identity and time boundary before collecting pages. If the source is live, specify whether the result describes a provider-supported snapshot or observations made during an interval. Do not quietly label the latter as every record that existed at one instant.

For a database query, ordering must be intentional. PostgreSQL's LIMIT and OFFSET documentation explains the need for a unique, predictable order when selecting subsets. A timestamp that several records share may need a stable tie-breaker. That addresses ambiguous ordering; it does not freeze a changing dataset.

A small local fixture exposes two different failures

We ran the following synthetic, in-memory example. It is not a test of GitHub, PostgreSQL or any customer's system. Start with ordered identities 1, 2, 3, 4, 5, 6, a page size of three, and a first page containing 1, 2, 3.

Compare an offset of three with a toy continuation that selects identities greater than 3:

Change before page two Offset result Toy keyset result
Add identity 0 at the front 3, 4, 5 4, 5, 6
Drop identity 1 5, 6 4, 5, 6

The insertion repeats identity 3 under the offset. The deletion causes identity 4 to be skipped. Deduplicating the first result removes the repeat but does not establish coverage; it cannot fix the second case's missing identity.

The toy keyset behaves more predictably for these particular changes, but it does not return the newly inserted 0. Whether that omission is acceptable depends on the intended population. The example also assumes immutable numeric ordering; it says nothing about an endpoint whose sort value changes during processing.

Keep the fixture and expected identities with the test. Counts alone can conceal a duplicate replacing a missing row.

Follow the endpoint's actual continuation contract

GitHub's REST pagination guide describes continuation through response link headers. Its GraphQL guide describes cursor-based traversal and page information. These are examples of contracts to read, not interchangeable pagination formats.

For the endpoint you operate, verify where continuation appears, what signals the end and which parameters must stay fixed. Treat opaque cursors as opaque. Do not construct the next page by guessing how a token encodes a row number.

A supplied URL also needs an approved destination policy. Do not forward an authorization header to an unexpected host merely because a response contains a link. Keep credentials, continuation tokens and private filters out of public logs.

Use a total page or time allowance. If the endpoint repeats the same continuation, fails or exceeds that allowance, stop with an explicit incomplete state. An error handler should not turn a partial list into a successful empty tail.

Change more than the number of rows

The insertion fixture is only a starting point. Test the following cases in an owned sandbox or a controlled local service:

  • Several records share the primary sort value. Verify the tie-breaker across page boundaries.
  • A record's sort value moves before or after the continuation boundary. Check the documented inclusion behavior.
  • A filterable field changes during the scan. State whether the reader needs membership at the start, at observation time or under a provider snapshot.
  • A record is deleted after it was read. Keep an observation distinct from a claim that it still exists.
  • A response contains fewer items than requested but still provides continuation. Follow the documented rule rather than a page-length assumption.
  • A continuation expires. Verify the supported recovery path and whether restarting changes the coverage window.

Declare expected outcomes before running the cases. When the source does not offer a required consistency guarantee, preserve that limitation instead of inventing a client-side promise.

Test interruption at the checkpoint boundary

Stop the reader after receiving a page but before its records are committed locally. Restart and inspect whether the page is replayed, skipped or reconciled under the intended policy. Then interrupt after local persistence but before saving continuation.

Saving the next cursor too early can lose work; replaying a page can repeat local effects. Decide what is committed together and how stable source identities are handled. A checkpoint is not evidence that downstream actions completed.

Keep the saved continuation bound to the same account, filters, sort, reader version and declared window. Reusing a cursor after changing those settings needs a provider-supported rule or a deliberate restart.

The asynchronous intake guide covers a different boundary: accepting work durably before processing it. Here, the question is which source records were actually observed and persisted.

Finish with a reconciliation statement

Report the scan's scope, start and end times, completion signal, unique identities observed, repeated identities and unresolved gaps. Use a source-supported manifest, snapshot or independent reconciliation where the task requires it. A provider total can be another observation, but confirm that it refers to the same population and time.

For a migration, connect this record to the export acceptance test. Pagination checks cannot prove that attachments, relationships or destination imports survived. They establish only the collection behavior you actually tested.

PainHunt's research guide can help turn a reported missing-record problem into questions to investigate. The provider contract, controlled fixture and reconciled observations remain the evidence for your own reader.

Frequently asked questions

Does a cursor guarantee a consistent snapshot?

No. A cursor is a continuation mechanism under an endpoint's contract. Check whether the provider actually promises snapshot consistency, how ordering works and what changes can appear during a scan. Do not infer those properties from an opaque token.

Should I stop when a page contains fewer records than requested?

Use the endpoint's documented completion signal. A short or empty page is not a universal end marker. Preserve the returned continuation and treat an error, repeated cursor or budget limit as an incomplete scan rather than a complete export.

Can deduplication repair a missed record?

It can remove repeated identities from the observations you collected. It cannot recover an identity that the scan never returned. Define a reconciliation method or a supported snapshot boundary if completeness is required.

Research the problem behind your idea

Explore problem summaries and source links to compare workflows and decide what to investigate next.

Open the Pain Point Browser

Related articles