+SKIP: {
+ skip 'TCP_DEFER_ACCEPT is Linux-only', 1 if $^O ne 'linux';
+ my $var = $TCP_DEFER_ACCEPT;
+ defined(my $x = getsockopt($sock, IPPROTO_TCP, $var)) or die;
+ is(unpack('i', $x), $defer_accept_val,
+ 'TCP_DEFER_ACCEPT unchanged if previously set');
+};
+SKIP: {
+ skip 'SO_ACCEPTFILTER is FreeBSD-only', 1 if $^O ne 'freebsd';
+ skip 'accf_data not loaded: kldload accf_data' if !defined $accf_arg;
+ my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
+ defined(my $x = getsockopt($sock, SOL_SOCKET, $var)) or die;
+ is($x, $accf_arg, 'SO_ACCEPTFILTER unchanged if previously set');
+};
+
+SKIP: {
+ skip 'only testing lsof(8) output on Linux', 1 if $^O ne 'linux';
+ my $lsof = which('lsof') or skip 'no lsof in PATH', 1;
+ my $null_in = '';
+ my $rdr = { 2 => \(my $null_err), 0 => \$null_in };
+ my @lsof = xqx([$lsof, '-p', $td->{pid}], undef, $rdr);
+ is_deeply([grep(/\bdeleted\b/, @lsof)], [], 'no lingering deleted inputs');
+
+ # filter out pipes inherited from the parent
+ my @this = xqx([$lsof, '-p', $$], undef, $rdr);
+ my $bad;
+ my $extract_inodes = sub {
+ map {;
+ my @f = split(' ', $_);
+ my $inode = $f[-2];
+ $bad = $_ if $inode !~ /\A[0-9]+\z/;
+ $inode => 1;
+ } grep (/\bpipe\b/, @_);
+ };
+ my %child = $extract_inodes->(@lsof);
+ my %parent = $extract_inodes->(@this);
+ skip("inode not in expected format: $bad", 1) if defined($bad);
+ delete @child{(keys %parent)};
+ is_deeply([], [keys %child], 'no extra pipes with -W0');
+};
+
+# ensure compatibility with other PSGI servers
+SKIP: {
+ require_mods(@zmods, qw(Plack::Test HTTP::Request::Common), 3);
+ use_ok 'HTTP::Request::Common';
+ use_ok 'Plack::Test';
+ STDERR->flush;
+ open my $olderr, '>&', \*STDERR or die "dup stderr: $!";
+ open my $tmperr, '+>', undef or die;
+ open STDERR, '>&', $tmperr or die;
+ STDERR->autoflush(1);
+ my $app = require $psgi;
+ test_psgi($app, sub {
+ my ($cb) = @_;
+ my $req = GET('http://example.com/psgi-return-gzip');
+ my $res = $cb->($req);
+ my $buf = $res->content;
+ IO::Uncompress::Gunzip::gunzip(\$buf => \(my $out));
+ is($out, "hello world\n", 'got expected output');
+
+ $req = GET('http://example.com/psgi-return-enoent');
+ $res = $cb->($req);
+ is($res->code, 500, 'got error on ENOENT');
+ seek($tmperr, 0, SEEK_SET) or die;
+ my $errbuf = do { local $/; <$tmperr> };
+ like($errbuf, qr/this-better-not-exist/,
+ 'error logged about missing command');
+ });
+ open STDERR, '>&', $olderr or die "restore stderr: $!";
+}
+