about summary refs log tree commit homepage
path: root/t/init.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-10-03 07:21:59 +0000
committerEric Wong <e@80x24.org>2019-10-05 06:54:00 +0000
commit6242da34fbe20940e3e258d2ec80e9aeef0438e1 (patch)
treec35bca08f9bf8f193debfd6f80902f640457abd6 /t/init.t
parent0e323a88eee90196392ef9a86bcd38159023550f (diff)
downloadpublic-inbox-6242da34fbe20940e3e258d2ec80e9aeef0438e1.tar.gz
First, we use flock(2) to wait on parallel public-inbox-init(1)
invocations while we make multiple changes using git-config(1).
This flock allows -init processes to wait on each other if using
reasonable POSIX filesystems.

Then, we also need a git-config(1)-compatible lock to prevent
user-invoked git-config(1) processes from clobbering our
changes while we're holding the flock.
Diffstat (limited to 't/init.t')
-rw-r--r--t/init.t12
1 files changed, 12 insertions, 0 deletions
diff --git a/t/init.t b/t/init.t
index 667b09fe..0cd6f31f 100644
--- a/t/init.t
+++ b/t/init.t
@@ -10,6 +10,8 @@ my $tmpdir = tempdir('pi-init-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 use constant pi_init => 'blib/script/public-inbox-init';
 use PublicInbox::Import;
 use File::Basename;
+use PublicInbox::Spawn qw(spawn);
+use Cwd qw(getcwd);
 open my $null, '>>', '/dev/null';
 my $rdr = { 2 => fileno($null) };
 sub quiet_fail {
@@ -47,6 +49,16 @@ sub quiet_fail {
         @cmd = (pi_init, 'clist', '-V2', "$tmpdir/clist",
                    qw(http://example.com/clist clist@example.com));
         quiet_fail(\@cmd, 'attempting to init V2 from V1 fails');
+
+        open my $lock, '+>', "$cfgfile.lock" or die;
+        @cmd = (getcwd(). '/'. pi_init, 'lock', "$tmpdir/lock",
+                qw(http://example.com/lock lock@example.com));
+        ok(-e "$cfgfile.lock", 'lock exists');
+        my $pid = spawn(\@cmd, undef, $rdr);
+        is(waitpid($pid, 0), $pid, 'lock init failed');
+        is($? >> 8, 255, 'got expected exit code on lock failure');
+        ok(unlink("$cfgfile.lock"),
+                '-init did not unlink lock on failure');
 }
 
 SKIP: {