about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-03-21 02:03:50 +0000
committerEric Wong <e@yhbt.net>2020-03-25 01:48:35 +0000
commitd111c17ff06c9af7e0690e4b00a0eeb1c505c92a (patch)
treea79425d1a90e4d940a40742ef90523bbb380f00e /t
parent90dc2b8ca53f93ca937e7cc71cd7c915e3df8020 (diff)
downloadpublic-inbox-d111c17ff06c9af7e0690e4b00a0eeb1c505c92a.tar.gz
As sqlite3(1) and other executables may become unavailable or
uninstalled while a daemon runs, we need to gracefully handle
errors in those cases.
Diffstat (limited to 't')
-rw-r--r--t/httpd-corner.psgi7
-rw-r--r--t/httpd-corner.t25
2 files changed, 31 insertions, 1 deletions
diff --git a/t/httpd-corner.psgi b/t/httpd-corner.psgi
index f2427234..44629620 100644
--- a/t/httpd-corner.psgi
+++ b/t/httpd-corner.psgi
@@ -94,6 +94,13 @@ my $app = sub {
                 return $qsp->psgi_return($env, undef, sub {
                         [ 200, [ qw(Content-Type application/octet-stream)]]
                 });
+        } elsif ($path eq '/psgi-return-enoent') {
+                require PublicInbox::Qspawn;
+                my $cmd = [ 'this-better-not-exist-in-PATH'.rand ];
+                my $qsp = PublicInbox::Qspawn->new($cmd);
+                return $qsp->psgi_return($env, undef, sub {
+                        [ 200, [ qw(Content-Type application/octet-stream)]]
+                });
         } elsif ($path eq '/pid') {
                 $code = 200;
                 push @$body, "$$\n";
diff --git a/t/httpd-corner.t b/t/httpd-corner.t
index e50aa436..cbfc8332 100644
--- a/t/httpd-corner.t
+++ b/t/httpd-corner.t
@@ -10,6 +10,7 @@ use PublicInbox::Spawn qw(which spawn);
 use PublicInbox::TestCommon;
 require_mods(qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status));
 use Digest::SHA qw(sha1_hex);
+use IO::Handle ();
 use IO::Socket;
 use IO::Socket::UNIX;
 use Fcntl qw(:seek);
@@ -336,6 +337,14 @@ SKIP: {
 }
 
 {
+        my $conn = conn_for($sock, 'psgi_return ENOENT');
+        print $conn "GET /psgi-return-enoent HTTP/1.1\r\n\r\n" or die;
+        my $buf = '';
+        sysread($conn, $buf, 16384, length($buf)) until $buf =~ /\r\n\r\n/;
+        like($buf, qr!HTTP/1\.[01] 500\b!, 'got 500 error on ENOENT');
+}
+
+{
         my $conn = conn_for($sock, '1.1 pipeline together');
         $conn->write("PUT /sha1 HTTP/1.1\r\nUser-agent: hello\r\n\r\n" .
                         "PUT /sha1 HTTP/1.1\r\n\r\n");
@@ -610,6 +619,11 @@ 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) = @_;
@@ -617,8 +631,17 @@ SKIP: {
                 my $res = $cb->($req);
                 my $buf = $res->content;
                 IO::Uncompress::Gunzip::gunzip(\$buf => \(my $out));
-                is($out, "hello world\n");
+                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: $!";
 }
 
 done_testing();