-if ($ENV{TEST_LEI_ONESHOT}) {
- require_ok 'PublicInbox::LEI';
- # force sun_path[108] overflow, ($lei->() filters out this path)
- my $xrd = "$home/1shot-test".('.sun_path' x 108);
- local $ENV{XDG_RUNTIME_DIR} = $xrd;
- $err_filter = qr!\Q$xrd!;
- $test_lei_common->();
-}
-
-SKIP: { # real socket
- require_mods(qw(Cwd), my $nr = 105);
- my $nfd = eval { require Socket::MsgHdr; 5 } // do {
- require PublicInbox::Spawn;
- PublicInbox::Spawn->can('send_cmd4') ? 5 : undef;
- } //
- skip 'Socket::MsgHdr or Inline::C missing or unconfigured', $nr;
-
- local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
- my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/$nfd.seq.sock";
-
- ok($lei->('daemon-pid'), 'daemon-pid');
- is($err, '', 'no error from daemon-pid');
- like($out, qr/\A[0-9]+\n\z/s, 'pid returned') or BAIL_OUT;
- chomp(my $pid = $out);
- ok(kill(0, $pid), 'pid is valid');
- ok(-S $sock, 'sock created');
-
- $test_lei_common->();
-
- ok($lei->('daemon-pid'), 'daemon-pid');
- chomp(my $pid_again = $out);
- is($pid, $pid_again, 'daemon-pid idempotent');
-
- ok($lei->(qw(daemon-kill)), 'daemon-kill');
- is($out, '', 'no output from daemon-kill');
- is($err, '', 'no error from daemon-kill');
- for (0..100) {
- kill(0, $pid) or last;
- tick();
- }
- ok(-S $sock, 'sock still exists');
- ok(!kill(0, $pid), 'pid gone after stop');
-
- ok($lei->(qw(daemon-pid)), 'daemon-pid');
- chomp(my $new_pid = $out);
- ok(kill(0, $new_pid), 'new pid is running');
- ok(-S $sock, 'sock still exists');
-
- for my $sig (qw(-0 -CHLD)) {
- ok($lei->('daemon-kill', $sig), "handles $sig");
- }
- is($out.$err, '', 'no output on innocuous signals');
- ok($lei->('daemon-pid'), 'daemon-pid');
- chomp $out;
- is($out, $new_pid, 'PID unchanged after -0/-CHLD');
-
- if ('socket inaccessible') {
- chmod 0000, $sock or BAIL_OUT "chmod 0000: $!";
- ok($lei->('help'), 'connect fail, one-shot fallback works');
- like($err, qr/\bconnect\(/, 'connect error noted');
- like($out, qr/^usage: /, 'help output works');
- chmod 0700, $sock or BAIL_OUT "chmod 0700: $!";
- }
- unlink $sock or BAIL_OUT "unlink($sock) $!";
- for (0..100) {
- kill('CHLD', $new_pid) or last;
- tick();
- }
- ok(!kill(0, $new_pid), 'daemon exits after unlink');
- # success over socket, can't test without
-};