about summary refs log tree commit homepage
path: root/t/spawn.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2024-01-30 07:22:21 +0000
committerEric Wong <e@80x24.org>2024-01-30 08:28:55 +0000
commit53eafcd90a3179200192263807cf3df7c869b500 (patch)
tree254a2f9cf1efc98f87b4ac453f69a4356ebac7cb /t/spawn.t
parent6b8bcf8bb0afc843e563862ae50a02d41aaba129 (diff)
downloadpublic-inbox-53eafcd90a3179200192263807cf3df7c869b500.tar.gz
BSD::Resource isn't packaged for Alpine (as of 3.19), but we
also have optional Inline::C support and already rely on calling
setrlimit(2) directly from the Inline::C version of pi_fork_exec.
Diffstat (limited to 't/spawn.t')
-rw-r--r--t/spawn.t21
1 files changed, 13 insertions, 8 deletions
diff --git a/t/spawn.t b/t/spawn.t
index 48f541b8..5b17ed38 100644
--- a/t/spawn.t
+++ b/t/spawn.t
@@ -6,7 +6,7 @@ use Test::More;
 use PublicInbox::Spawn qw(which spawn popen_rd run_qx);
 require PublicInbox::Sigfd;
 require PublicInbox::DS;
-
+my $rlimit_map = PublicInbox::Spawn->can('rlimit_map');
 {
         my $true = which('true');
         ok($true, "'true' command found with which()");
@@ -192,14 +192,19 @@ EOF
 }
 
 SKIP: {
-        eval {
-                require BSD::Resource;
-                defined(BSD::Resource::RLIMIT_CPU())
-        } or skip 'BSD::Resource::RLIMIT_CPU missing', 3;
+        if ($rlimit_map) { # Inline::C installed
+                my %rlim = $rlimit_map->();
+                ok defined($rlim{RLIMIT_CPU}), 'RLIMIT_CPU defined';
+        } else {
+                eval {
+                        require BSD::Resource;
+                        defined(BSD::Resource::RLIMIT_CPU())
+                } or skip 'BSD::Resource::RLIMIT_CPU missing', 3;
+        }
         my $cmd = [ $^X, qw(-w -e), <<'EOM' ];
 use POSIX qw(:signal_h);
-use BSD::Resource qw(times);
 use Time::HiRes qw(time); # gettimeofday
+my $have_bsd_resource = eval { require BSD::Resource };
 my $set = POSIX::SigSet->new;
 $set->emptyset; # spawn() defaults to blocking all signals
 sigprocmask(SIG_SETMASK, $set) or die "SIG_SETMASK: $!";
@@ -211,10 +216,10 @@ while (1) {
         # and `write' (via Perl warn)) on otherwise idle systems to
         # hit RLIMIT_CPU and fire signals:
         # https://marc.info/?i=02A4BB8D-313C-464D-845A-845EB6136B35@gmail.com
-        my @t = times;
+        my @t = $have_bsd_resource ? BSD::Resource::times() : (0, 0);
         $tot = $t[0] + $t[1];
         if (time > $next) {
-                warn "# T: @t (utime, ctime, cutime, cstime)\n";
+                warn "# T: @t (utime, ctime, cutime, cstime)\n" if @t;
                 $next = time + 1.1;
         }
 }