Skip to content

test(session): cover the reachable error paths of the durability fix - #476

Merged
dimetron merged 1 commit into
mainfrom
test/session-error-paths
Nov 15, 2026
Merged

dimetron merged 1 commit into
mainfrom
test/session-error-paths

Conversation

@dimetron

Copy link
Copy Markdown
Owner

Follow-up to #475, which merged before this commit's CI run finished. The
durability fix is on main; only its error-path tests were left behind.

Tests only — no production code changes.

What this adds

Four error paths of the #475 fix that had no coverage:

Test Guards
TestAppendEventToFile_ErrorWhenSessionDirMissing a missing session dir fails the open instead of looking like a successful write
TestRewriteEvents_ErrorWhenSessionDirMissing same, for the compaction rewrite
TestWriteFileAtomic_ErrorWhenDirMissing meta/branch writes report a missing parent dir
TestLeftJoin_ErrorOnClosedFile a stat failure surfaces instead of passing silently

The leftJoin one matters most: if that error were swallowed, the next append
would concatenate onto a torn tail and corrupt two records instead of one.

Verified

TestLeftJoin_ErrorOnClosedFile fails when the behaviour regresses — changed the
return data, err to return data, nil and the guard went red with
leftJoin() = nil error on a closed file, want the stat failure, then restored.

go test ./internal/session/, go vet, golangci-lint all clean.

Deliberately not covered

The remaining uncovered lines in store.go are branches that need the OS to
fail a syscall that succeeds in a test — Sync returning an error, ReadAt
failing on a readable file, MkdirAll/CreateTemp on a healthy filesystem.
Covering those needs a fault-injecting filesystem, which this change does not
justify. Note also that TestAppendEventToFile_IsSynced still passes with the
Sync call removed: nothing in-process simulates power loss, so that assertion
verifies the file is complete and newline-terminated, not that it was synced.

Codecov flagged 11 uncovered added lines. These are the ones a test can
actually reach: a missing session directory must fail the open rather than
look like a successful write, a closed handle must fail leftJoin's stat
instead of passing silently, and rewriteEvents/writeFileAtomic must report
a missing parent directory.

The lines still uncovered are the branches that require the operating
system to fail a syscall that succeeds in a test — Sync returning an error,
ReadAt failing on a readable file, MkdirAll/CreateTemp on a healthy
filesystem. Covering those needs a fault-injecting filesystem, which is a
dependency this change does not justify; left uncovered deliberately.

Signed-off-by: pi <dimetron@me.com>
@dimetron
dimetron merged commit 6c1a7ae into main Nov 15, 2026
13 checks passed
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.59%. Comparing base (081acb3) to head (8f0929d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #476   +/-   ##
=======================================
  Coverage   91.58%   91.59%           
=======================================
  Files         391      391           
  Lines       50292    50292           
=======================================
+ Hits        46062    46065    +3     
+ Misses       4224     4221    -3     
  Partials        6        6           

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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