From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 4E72D1F452 for ; Tue, 28 Nov 2023 14:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1701183388; bh=dWqNj2lmPj3khlAkrOH/BmmZa7eNny5sm9W32Tjr0nE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Xq4wq+09sSAEDh07WaoyHBsd65sfoqaQfzygUoloMc6RPhy9wpZKXSHOl8TZDoi3o IHGAQB3uQ91nxboUxd5/5GR5EngeDClXOqsORbXPj9Ezr3DT+KcbqwGtrN6WUZV0Bi N/B605Pdir266nvnXIYDCXGtg7qtSYujJn/5ZXLE= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 01/14] test_common: create_*: detect changes all parameters Date: Tue, 28 Nov 2023 14:56:14 +0000 Message-ID: <20231128145628.1455176-2-e@80x24.org> In-Reply-To: <20231128145628.1455176-1-e@80x24.org> References: <20231128145628.1455176-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Data::Dumper+B::Deparse seems fast enough to generate cache keys with, so this makes updating and developing tests easier (as opposed to forcing the developer to change the identifier). The main downside is we'll have to deal with cache expiration, but "make clean" seems overly aggressive already (it keeps blowing away the clones made by t/cindex-join.t :<) --- lib/PublicInbox/TestCommon.pm | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 361a2356..8e7eb950 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -793,6 +793,19 @@ our %COMMIT_ENV = ( GIT_COMMITTER_EMAIL => 'c@example.com', ); +# for memoizing based on coderefs and various create_* params +sub my_sum { + require PublicInbox::SHA; + require Data::Dumper; + my $d = Data::Dumper->new(\@_); + $d->$_(1) for qw(Deparse Sortkeys Terse); + my @l = split /\n/s, $d->Dump; + @l = grep !/\$\^H\{.+?[A-Z]+\(0x[0-9a-f]+\)/, @l; # autodie addresses + my @addr = grep /[A-Za-z]+\(0x[0-9a-f]+\)/, @l; + xbail 'undumpable addresses: ', \@addr if @addr; + substr PublicInbox::SHA::sha256_hex(join('', @l)), 0, 8; +} + sub create_coderepo ($$;@) { my $ident = shift; my $cb = pop; @@ -801,15 +814,12 @@ sub create_coderepo ($$;@) { require PublicInbox::Import; my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!); my ($db) = (PublicInbox::Import::default_branch() =~ m!([^/]+)\z!); - my $dir = "t/data-gen/$base.$ident-$db"; - my $new = !-d $dir; - if ($new && !CORE::mkdir($dir)) { - my $err = $!; - -d $dir or xbail "mkdir($dir): $err"; - } + my $tmpdir = delete $opt{tmpdir}; + my $dir = "t/data-gen/$base.$ident-".my_sum($db, $cb, \%opt); + require File::Path; + my $new = File::Path::make_path($dir); my $lk = PublicInbox::Lock->new("$dir/creat.lock"); my $scope = $lk->lock_for_scope; - my $tmpdir = delete $opt{tmpdir}; if (!-f "$dir/creat.stamp") { opendir(my $dfh, '.'); chdir($dir); @@ -832,12 +842,10 @@ sub create_inbox ($;@) { require PublicInbox::Import; my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!); my ($db) = (PublicInbox::Import::default_branch() =~ m!([^/]+)\z!); - my $dir = "t/data-gen/$base.$ident-$db"; - my $new = !-d $dir; - if ($new && !mkdir($dir)) { - my $err = $!; - -d $dir or xbail "mkdir($dir): $err"; - } + my $tmpdir = delete $opt{tmpdir}; + my $dir = "t/data-gen/$base.$ident-".my_sum($db, $cb, \%opt); + require File::Path; + my $new = File::Path::make_path($dir); my $lk = PublicInbox::Lock->new("$dir/creat.lock"); $opt{inboxdir} = File::Spec->rel2abs($dir); $opt{name} //= $ident; @@ -846,7 +854,6 @@ sub create_inbox ($;@) { $pre_cb->($dir) if $pre_cb && $new; $opt{-no_fsync} = 1; my $no_gc = delete $opt{-no_gc}; - my $tmpdir = delete $opt{tmpdir}; my $addr = $opt{address} // []; $opt{-primary_address} //= $addr->[0] // "$ident\@example.com"; my $parallel = delete($opt{importer_parallel}) // 0;