From patchwork Mon Aug 5 13:07:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13753604 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 64D0518026 for ; Mon, 5 Aug 2024 13:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722863277; cv=none; b=ZZ0WABxTfaI7YKOYIHmdP9dRQYp4I0PLFdbHcdNQdAbGUTsfvFUBGNqooDcqBHjZHDj/WaLmyE0u/z0PpuILQcOfQRywSJwRy3nn0jGUmffVDXFhW+/HalDjK+XINQQSo4Q0S0oCzZq39rI0Lfl4ePEyPYK6WhrFyb2r9g33jvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722863277; c=relaxed/simple; bh=XEWq3KR9I/V5/i/SDtdq4W8BZ2oOmhqqTWQGG5klV20=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f8IRRGgWS/6lE/ME/jwfrOh7EMW3qoP2hsy2tD23IsLTrFiQaOSj15RSA7pSx2bgzjoOdP+fI0M2qYs5DftQC3Vyll8DV3GGVld+FOdTqGsXmoesZya80hUewU8EckK34LgUS5VXquDkpwUSS/pqYkbMEjpagtKgQ6BA2SSW9Ro= 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=R13E3kpB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Qs/dNvee; arc=none smtp.client-ip=103.168.172.145 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="R13E3kpB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Qs/dNvee" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 7F599138FC9F; Mon, 5 Aug 2024 09:07:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 05 Aug 2024 09:07:54 -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=1722863274; x=1722949674; bh=rBvmoj3Swq YFoQXdXyqaVU73L9bpPx2rG2VK8oiciPQ=; b=R13E3kpBgWTc8uOJgcJNFrOzMl Jev9JCtejiTDhOpV1xpxrV3WnRXpJeqKKYFJuDggSK8BRa6HwME9OgaWn3Ycgd/x tB9S8LieTMcvBTAKGWr9O0R6WpHd87oXuN2NcV30hhIodCY0h7aeMqyt7gUL7ygH w/fi2W/phZFShNSp0sl9vo7ER5blu4wS0JwWpepQ3slfrG2y25JQ82kGXYZfl1iP VU0z7fuZuoBd+Nvwa2wkWmG5KGL7CRAvPb9357hHdaF1vP99FM8Dmz0wh/VWEX0n c3qijhXT4GM9FNVSRfLUGPEPpGKjOWozUDG8SICE20bxLWwjYDyy0nnR2RFQ== 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=1722863274; x=1722949674; bh=rBvmoj3SwqYFoQXdXyqaVU73L9bp Px2rG2VK8oiciPQ=; b=Qs/dNveet+GWwrE5ZTtZA1z7rLVMytKSOi+h+jCWqv3p PkFUxth0lWW1IMXdLBvTx4IZlHaRrWKY+gXNoWgY69g2KECeDZql4vG9HOe86Zz2 Fdt++UELTWFHQ3h39IRL3WIoBXVQX13wOGvd1TmcWzJJD2wZYOHItpCkpDji+qjV nQs10eNJ67aKcSgVf2Dp/D5HXZkgtpxDlIdfrjwlykZfrtVfVsSm2yhyN/tQVPZu 0ftraWWA5MWGiTQO9BjLzxMCiT+PtMcws9C2HQiXKAOmRvxusvSCm5CW9/TMhOxt TbgFME453j2syMy6iUjXPr5MJXxxHbdGlCvbOuTt3g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigdeiudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 09:07:53 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1d0a281f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 5 Aug 2024 13:07:53 +0000 (UTC) Date: Mon, 5 Aug 2024 15:07:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 2/9] reftable/stack: extract function to setup stack with N tables Message-ID: 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. Signed-off-by: Patrick Steinhardt --- reftable/stack_test.c | 60 ++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/reftable/stack_test.c b/reftable/stack_test.c index e3c11e6a6e..61dddf7f69 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -109,6 +109,30 @@ 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, + struct reftable_write_options *opts, + size_t n) +{ + struct strbuf buf = STRBUF_INIT; + int err; + + 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); + } + + strbuf_release(&buf); +} + struct write_log_arg { struct reftable_log_record *log; uint64_t update_index; @@ -916,25 +940,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, &opts, 3); err = reftable_new_stack(&st2, dir, &opts); EXPECT_ERR(err); @@ -965,25 +975,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, &opts, 3); err = reftable_new_stack(&st2, dir, &opts); EXPECT_ERR(err);