From 061df987a35b59efce4a5b7aed604ed9cf7e0c8c Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sat, 29 Aug 2026 20:39:56 -0500 Subject: [PATCH] test atomic section error paths and nesting Covers UnbalancedAtomic from an unmatched endAtomic, nested sections, and that a balanced pair succeeds on a read-only database. The XapianException path is not externally triggerable: probing shows even a closed database returns success since the atomic calls only touch a counter unless the database is open read-write. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_017i7R7ReKJAHGQpitxGXqrb --- src/tests.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tests.zig b/src/tests.zig index 1751dc1..eb58ea2 100644 --- a/src/tests.zig +++ b/src/tests.zig @@ -139,6 +139,28 @@ test "Database atomic sections" { try std.testing.expect(hasTag(&tags, "atomic-test")); } +test "Database atomic section error paths" { + var test_db = try fixture.corpusDatabase(); + defer test_db.deinit(); + const db = test_db.database; + + // endAtomic without a matching beginAtomic is unbalanced. + try std.testing.expectError(error.UnbalancedAtomic, db.endAtomic()); + + // Atomic sections nest; the extra endAtomic is unbalanced again. + try db.beginAtomic(); + try db.beginAtomic(); + try db.endAtomic(); + try db.endAtomic(); + try std.testing.expectError(error.UnbalancedAtomic, db.endAtomic()); + + // On a read-only database notmuch does not open a Xapian transaction, so + // a balanced pair still succeeds. + try test_db.database.reopen(.read_only); + try db.beginAtomic(); + try db.endAtomic(); +} + test "Database.getDirectory and Directory" { const alloc = std.testing.allocator; var test_db = try fixture.corpusDatabase(); -- 2.51.2