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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 11, 2023 at 10:07 UTC
15f98b602f36ce5e5cc1f466850eaf2b37022e3b
1 file changed
+49
reftable/stack_test.c
+49
@@ -850,6 +850,54 @@ static void test_reftable_stack_auto_compaction(void)
850
clear_dir(dir);
851
}
852
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
+
901
static void test_reftable_stack_compaction_concurrent(void)
902
{
903
struct reftable_write_options cfg = { 0 };
@@ -960,6 +1008,7 @@ int stack_test_main(int argc, const char *argv[])
1008
RUN_TEST(test_reftable_stack_add);
1009
RUN_TEST(test_reftable_stack_add_one);
1010
RUN_TEST(test_reftable_stack_auto_compaction);
1011
+ RUN_TEST(test_reftable_stack_add_performs_auto_compaction);
1012
RUN_TEST(test_reftable_stack_compaction_concurrent);
1013
RUN_TEST(test_reftable_stack_compaction_concurrent_clean);
1014
RUN_TEST(test_reftable_stack_hash_id);