From patchwork Thu Aug 8 14:06:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13757510 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C03118C33B for ; Thu, 8 Aug 2024 14:06:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723125990; cv=none; b=VtzpKqnohJXPBo7V3lEEZYT9Ye7mkpH9eEFzedzlr41BY+dmTLAA572QGom4GBofWHhyLUdQkyEcr4cBbxR6D4hYSEZbOColFeQNIW1o6/Oef7hdDdb2jf/cnmE6BoBGCBJz/mPhGLn03VNaUwyViB10G6ViJeHg7IgZM69dX/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723125990; c=relaxed/simple; bh=Vd7rfmXPLBH0DsiVDfHkK1o8aPw4euFlYZ7rIrKnSiY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bpq0kopelgxKl/SETQnE5J/WlXu05rMdph9ogdfBpRO/a8xbiQGJEMQmnMVXICyZWTfyC8u+usrVgpy/kGHP3jjSI9tOrvKr4o3nPcVOmi1cCSA3+SdMWv7bTkWwDEeUOE+zEjhFULAfOiN+4SSgJMXUZ5vxtODv/DV/kR4ZuqU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=FvrXRG0M; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iBP21AAL; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="FvrXRG0M"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iBP21AAL" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 0600F11517A4; Thu, 8 Aug 2024 10:06:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 08 Aug 2024 10:06:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723125988; x=1723212388; bh=mYMhjsUsxE 3oB6YPAnVKvVYgNUtOqGe4p2GGjMebQ5w=; b=FvrXRG0MHGXUreCKLUM9whcazk kiiGjbg/yyFMK3+pPgwWfbyDLzTol90NTi/KQMt9O/62kUgNoEh5aESgdaSnJFGq cE81WYyBp6CZFCO/ER8CmMegDG0N02qmbvR+V4A5rbZx1glNge/jeDx8ifNhywne jY/X+JhNxxUGeRLNHdvuqxHvF8lQG5Oad+fnuO/7FOsWJWZSjHAvB7/Cdzg15Hdl jshHXjE96HW+XMXpk5ITzf++z6WA6ucl68qcOl5l3k7BoyvfrFuP1LgIW8wVnKfO nWVvLaqn/wqgQLGlgs1ADxV2OVTm6QcOsWctnt1/Jr4YtGmeVITpAvFur+Fg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723125988; x=1723212388; bh=mYMhjsUsxE3oB6YPAnVKvVYgNUtO qGe4p2GGjMebQ5w=; b=iBP21AALFgKkWI5/9i9DyhR8rYbHpra0uKNmUNEyFG55 nT95Rt50NMNCUYehfM6bje2cy1mRUnha3hzUgk+5+v1dOYrDYbHu5L0JcH/yzcls i+mD1I7dMP7d7RKRLyoabzdWWicsm0Qx/HGEXSuf386QX1mRG9ma6dUS3+CKO0uZ EutEs+lEgSo8x6NBbP14Cz+ctcfW/oMqDsgbnknk+iYAqB66ROQhNwyLtW8OBObO 2cN1iRLuF7/d86NnKMv8MgoPI5lnbqkH7dRs19rkgCLlmYL4A6V6sO9ebK/qc6Dh r7L6SyX0hDjN1j6ZlqNnJ5jRXWnKkRFap7TvfDcOzg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrledvgdejvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqe enucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeeh gfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeegpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpth htohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrghrthhhihhkrddukeeksehgmh grihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Aug 2024 10:06:26 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f713fedf (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Aug 2024 14:06:19 +0000 (UTC) Date: Thu, 8 Aug 2024 16:06:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano , Karthik Nayak Subject: [PATCH v3 2/9] reftable/stack: extract function to setup stack with N tables Message-ID: <798a661824cfaa93160636e91b745b57e2d52776.1723123606.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We're about to add two tests, and both of them will want to initialize the reftable stack with a set of N tables. Introduce a new function that handles this and refactor existing tests that use such a setup to use it. Note that this changes the exact records contained in the preexisting tests. This is fine though as we only care about the shape of the stack here, not the shape of each table. Furthermore, with this change we now start to disable auto compaction when writing the tables, as otherwise we might not end up with the expected amount of new tables added. This also slightly changes the behaviour of these tests, but the properties we care for remain intact. Signed-off-by: Patrick Steinhardt --- reftable/stack_test.c | 64 +++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/reftable/stack_test.c b/reftable/stack_test.c index e3c11e6a6e..0b110f6f02 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -109,6 +109,34 @@ static int write_test_ref(struct reftable_writer *wr, void *arg) return reftable_writer_add_ref(wr, ref); } +static void write_n_ref_tables(struct reftable_stack *st, + size_t n) +{ + struct strbuf buf = STRBUF_INIT; + int disable_auto_compact; + int err; + + disable_auto_compact = st->opts.disable_auto_compact; + st->opts.disable_auto_compact = 1; + + for (size_t i = 0; i < n; i++) { + struct reftable_ref_record ref = { + .update_index = reftable_stack_next_update_index(st), + .value_type = REFTABLE_REF_VAL1, + }; + + strbuf_addf(&buf, "refs/heads/branch-%04u", (unsigned) i); + ref.refname = buf.buf; + set_test_hash(ref.value.val1, i); + + err = reftable_stack_add(st, &write_test_ref, &ref); + EXPECT_ERR(err); + } + + st->opts.disable_auto_compact = disable_auto_compact; + strbuf_release(&buf); +} + struct write_log_arg { struct reftable_log_record *log; uint64_t update_index; @@ -916,25 +944,11 @@ static void test_reftable_stack_compaction_concurrent(void) struct reftable_write_options opts = { 0 }; struct reftable_stack *st1 = NULL, *st2 = NULL; char *dir = get_tmp_dir(__LINE__); - int err, i; - int N = 3; + int err; err = reftable_new_stack(&st1, dir, &opts); EXPECT_ERR(err); - - for (i = 0; i < N; i++) { - char name[100]; - struct reftable_ref_record ref = { - .refname = name, - .update_index = reftable_stack_next_update_index(st1), - .value_type = REFTABLE_REF_SYMREF, - .value.symref = (char *) "master", - }; - snprintf(name, sizeof(name), "branch%04d", i); - - err = reftable_stack_add(st1, &write_test_ref, &ref); - EXPECT_ERR(err); - } + write_n_ref_tables(st1, 3); err = reftable_new_stack(&st2, dir, &opts); EXPECT_ERR(err); @@ -965,25 +979,11 @@ static void test_reftable_stack_compaction_concurrent_clean(void) struct reftable_write_options opts = { 0 }; struct reftable_stack *st1 = NULL, *st2 = NULL, *st3 = NULL; char *dir = get_tmp_dir(__LINE__); - int err, i; - int N = 3; + int err; err = reftable_new_stack(&st1, dir, &opts); EXPECT_ERR(err); - - for (i = 0; i < N; i++) { - char name[100]; - struct reftable_ref_record ref = { - .refname = name, - .update_index = reftable_stack_next_update_index(st1), - .value_type = REFTABLE_REF_SYMREF, - .value.symref = (char *) "master", - }; - snprintf(name, sizeof(name), "branch%04d", i); - - err = reftable_stack_add(st1, &write_test_ref, &ref); - EXPECT_ERR(err); - } + write_n_ref_tables(st1, 3); err = reftable_new_stack(&st2, dir, &opts); EXPECT_ERR(err);