Skip to content

test(C): exercise reads on an empty DB in delete_all_keys#5

Open
ALH477 wants to merge 1 commit into
mainfrom
test/delete-all-empty-read
Open

test(C): exercise reads on an empty DB in delete_all_keys#5
ALH477 wants to merge 1 commit into
mainfrom
test/delete-all-empty-read

Conversation

@ALH477

@ALH477 ALH477 commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Strengthens the existing delete_all_keys test (C reference impl).

Today it deletes both keys then re-inserts, but never reads the now-empty database — and a read is exactly what dereferences db->root. This adds, right after the two deletes:

size_t vsize = 0;
ASSERT_NULL(streamdb_get(db, (const unsigned char*)"a", 1, &vsize));
StreamDBResult* empty = streamdb_suffix_search(db, (const unsigned char*)"a", 1);
ASSERT_NULL(empty);
streamdb_free_results(empty);

This locks in the "root is never NULL" guard in streamdb_delete (which re-seeds an empty root after the prune frees it). An earlier reverse-trie variant lacking that guard segfaulted on exactly this path (a get/suffix_search after the last key is deleted) — heap-layout-sensitive, so it looked intermittent. Current main already handles it; this test makes that explicit and guards against regressions.

Test-only change. Full suite passes locally (24/24) under the repo's -Werror -pedantic build:

delete_all_keys                                    [PASS]
Results: 24 passed, 0 failed

Context: opened from #4.

🤖 Generated with Claude Code

delete_all_keys deleted both keys then re-inserted, but never read the
now-empty database. Add assertions that streamdb_get and
streamdb_suffix_search on the emptied DB return "not found" without
crashing — the exact operations that dereference db->root.

This locks in the "root is never NULL" guard in streamdb_delete (which
re-seeds an empty root after the prune frees it) against regressions: an
earlier reverse-trie variant without that guard segfaulted here.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

2 participants