user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <20231128145628.1455176-2-e@80x24.org> (raw)
In-Reply-To: <20231128145628.1455176-1-e@80x24.org>

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;

  reply	other threads:[~2023-11-28 14:56 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28 14:56 [PATCH 00/14] IT'S ALIVE! www loads cindex join data Eric Wong
2023-11-28 14:56 ` Eric Wong [this message]
2023-11-28 14:56 ` [PATCH 02/14] t/cindex*: require SCM_RIGHTS for these tests Eric Wong
2024-01-29 21:23   ` [PATCH 0/2] pure Perl sendmsg/recvmsg on *BSD Eric Wong
2024-01-29 21:23     ` [PATCH 1/2] syscall: update formatting to match our codebase Eric Wong
2024-01-29 21:23     ` [PATCH 2/2] syscall: use pure Perl sendmsg/recvmsg on *BSD Eric Wong
2024-04-06  0:43       ` Gaelan Steele
2024-04-08  9:48         ` [RFT] syscall: set default constants for Inline::C platforms Eric Wong
2024-04-08 12:12           ` Gaelan Steele
2024-04-08 20:11             ` Eric Wong
2023-11-28 14:56 ` [PATCH 03/14] codesearch: eliminate redundant substitutions Eric Wong
2023-11-28 14:56 ` [PATCH 04/14] solver: schedule cleanup after synchronous git->check Eric Wong
2023-11-28 14:56 ` [PATCH 05/14] xap_helper.h: move cindex endpoints to separate file Eric Wong
2023-11-28 14:56 ` [PATCH 06/14] xap_helper: implement mset endpoint for WWW, IMAP, etc Eric Wong
2023-11-28 14:56 ` [PATCH 07/14] hval: use File::Spec to make relative paths for href Eric Wong
2023-11-28 14:56 ` [PATCH 08/14] www: load and use cindex join data Eric Wong
2023-11-28 14:56 ` [PATCH 09/14] git: speed up ->git_path for non-worktrees Eric Wong
2023-11-28 14:56 ` [PATCH 10/14] cindex: require `-g GIT_DIR' or `-r PROJECT_ROOT' Eric Wong
2023-11-28 14:56 ` [PATCH 11/14] git: speed up Git->new by 5% or so Eric Wong
2023-11-28 14:56 ` [PATCH 12/14] admin: resolve_git_dir respects symlinks Eric Wong
2023-11-28 14:56 ` [PATCH 13/14] cindex: extra quit checks Eric Wong
2023-11-28 14:56 ` [PATCH 14/14] www: start working on a repo listing Eric Wong
2023-11-28 17:55 ` [PATCH 15/14] www: load cindex join data for ->ALL, too Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231128145628.1455176-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).