Skip to content

Commit 15f98b6

Browse files
pks-tgitster
authored andcommitted
reftable/stack: verify that reftable_stack_add() uses auto-compaction
While we have several tests that check whether we correctly perform auto-compaction when manually calling `reftable_stack_auto_compact()`, we don't have any tests that verify whether `reftable_stack_add()` does call it automatically. Add one. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 85a8c89 commit 15f98b6

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

reftable/stack_test.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,54 @@ static void test_reftable_stack_auto_compaction(void)
850850
clear_dir(dir);
851851
}
852852

853+
static void test_reftable_stack_add_performs_auto_compaction(void)
854+
{
855+
struct reftable_write_options cfg = { 0 };
856+
struct reftable_stack *st = NULL;
857+
struct strbuf refname = STRBUF_INIT;
858+
char *dir = get_tmp_dir(__LINE__);
859+
int err, i, n = 20;
860+
861+
err = reftable_new_stack(&st, dir, cfg);
862+
EXPECT_ERR(err);
863+
864+
for (i = 0; i <= n; i++) {
865+
struct reftable_ref_record ref = {
866+
.update_index = reftable_stack_next_update_index(st),
867+
.value_type = REFTABLE_REF_SYMREF,
868+
.value.symref = "master",
869+
};
870+
871+
/*
872+
* Disable auto-compaction for all but the last runs. Like this
873+
* we can ensure that we indeed honor this setting and have
874+
* better control over when exactly auto compaction runs.
875+
*/
876+
st->disable_auto_compact = i != n;
877+
878+
strbuf_reset(&refname);
879+
strbuf_addf(&refname, "branch-%04d", i);
880+
ref.refname = refname.buf;
881+
882+
err = reftable_stack_add(st, &write_test_ref, &ref);
883+
EXPECT_ERR(err);
884+
885+
/*
886+
* The stack length should grow continuously for all runs where
887+
* auto compaction is disabled. When enabled, we should merge
888+
* all tables in the stack.
889+
*/
890+
if (i != n)
891+
EXPECT(st->merged->stack_len == i + 1);
892+
else
893+
EXPECT(st->merged->stack_len == 1);
894+
}
895+
896+
reftable_stack_destroy(st);
897+
strbuf_release(&refname);
898+
clear_dir(dir);
899+
}
900+
853901
static void test_reftable_stack_compaction_concurrent(void)
854902
{
855903
struct reftable_write_options cfg = { 0 };
@@ -960,6 +1008,7 @@ int stack_test_main(int argc, const char *argv[])
9601008
RUN_TEST(test_reftable_stack_add);
9611009
RUN_TEST(test_reftable_stack_add_one);
9621010
RUN_TEST(test_reftable_stack_auto_compaction);
1011+
RUN_TEST(test_reftable_stack_add_performs_auto_compaction);
9631012
RUN_TEST(test_reftable_stack_compaction_concurrent);
9641013
RUN_TEST(test_reftable_stack_compaction_concurrent_clean);
9651014
RUN_TEST(test_reftable_stack_hash_id);

0 commit comments

Comments
 (0)