Skip to content

Add Session.TxResults - #22

Merged
winebarrel merged 1 commit into
mainfrom
tx-results
Nov 8, 2026
Merged

winebarrel merged 1 commit into
mainfrom
tx-results

Conversation

@winebarrel

Copy link
Copy Markdown
Owner

Summary

  • Add Session.TxResults, which returns how the application transactions of every *sql.DB of the session ended, in order. It records outcomes rather than calls, so tx.Rollback() after Commit is not counted.
  • TxCommitted: Commit succeeded.
  • TxRolledBack: Rollback was called, or the transaction's context was canceled.
  • TxCommitFailed: Commit was called but did not commit, such as when the transaction had hit an error.
  • TxResults does not wait for the session, so it can be called while a transaction is open. A transaction that is still open is not included.
  • Update docs, README and tests.
s := sandpit.Session(t)

err := svc.Transfer(ctx, s.DB(), from, to, 100)
require.Error(t, err)

assert.Equal(t, []pgsandpit.TxResult{pgsandpit.TxRolledBack}, s.TxResults())

database/sql rolls back a canceled transaction in another goroutine, so its result may appear shortly after the cancellation. This comes from reading database/sql; the test waits with assert.Eventually and does not reproduce the delay itself.

Test plan

  • make vet
  • go test -race -count=1 ./...
  • go test -race -count=20 -run 'TestTxResults|TestTxResultString' ./...
  • golangci-lint run

Session.TxResults returns how the application transactions of every
*sql.DB of the session ended, in order, so that a test can check that the
code under test committed or rolled back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.44%. Comparing base (600a6de) to head (60e7bdb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #22      +/-   ##
==========================================
+ Coverage   91.92%   92.44%   +0.51%     
==========================================
  Files           6        6              
  Lines         322      344      +22     
==========================================
+ Hits          296      318      +22     
  Misses         14       14              
  Partials       12       12              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@winebarrel
winebarrel merged commit 3eee5a1 into main Nov 8, 2026
4 checks passed
@winebarrel
winebarrel deleted the tx-results branch November 8, 2026 08:07
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.

1 participant