about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <mwrap-perl@80x24.org>2022-12-11 06:29:47 +0000
committerEric Wong <mwrap-perl@80x24.org>2022-12-11 06:31:17 +0000
commita62fd3fd047eeb2b4b085321082e210b97802044 (patch)
treeb5d48bad7379a73c015936d514b439575a82da3d
parent6dac55bd7c0aa4bcb54da894ffcd80d1f0534134 (diff)
downloadmwrap-a62fd3fd047eeb2b4b085321082e210b97802044.tar.gz
Using a FIFO in Perl means our mwrap_ctor constructor has
already run and bound the listen socket.  So using it as a
synchronization barrier means we can rely on it to ensure
the socket is connect-able.
-rw-r--r--t/mwrap-httpd.t21
1 files changed, 12 insertions, 9 deletions
diff --git a/t/mwrap-httpd.t b/t/mwrap-httpd.t
index b7076de..73b704e 100644
--- a/t/mwrap-httpd.t
+++ b/t/mwrap-httpd.t
@@ -7,9 +7,12 @@ use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC);
 use POSIX qw(dup2 _exit mkfifo);
 BEGIN { require './t/test_common.perl' };
 my $env = { MWRAP => "socket_dir:$mwrap_tmp" };
-my $fifo = "$mwrap_tmp/fifo";
-mkfifo($fifo, 0600) // plan(skip_all => "mkfifo: $!");
-my $pid = mwrap_run('httpd test', $env, '-e', "open my \$fh, '<', '$fifo'");
+my $f1 = "$mwrap_tmp/f1";
+my $f2 = "$mwrap_tmp/f2";
+mkfifo($f1, 0600) // plan(skip_all => "mkfifo: $!");
+mkfifo($f2, 0600) // plan(skip_all => "mkfifo: $!");
+my $pid = mwrap_run('httpd test', $env, '-e',
+        "open my \$f1, '>', '$f1'; close \$f1; open my \$f2, '<', '$f2'");
 my $spid;
 my $mw_exit;
 my $cleanup = sub {
@@ -25,7 +28,7 @@ my $cleanup = sub {
         use autodie;
         if (defined $pid) {
                 my $exit = $?;
-                open my $fh, '>', $fifo;
+                open my $fh, '>', $f2;
                 close $fh;
                 waitpid($pid, 0);
                 $mw_exit = $?;
@@ -39,12 +42,12 @@ END { $cleanup->() }
 my $sock = "$mwrap_tmp/$pid.sock";
 my %o = (Peer => $sock , Type => SOCK_STREAM);
 local $SIG{PIPE} = 'IGNORE';
-my $c;
-for (1..10000) {
-        last if -S $sock && ($c = IO::Socket::UNIX->new(%o));
-        select undef, undef, undef, 0.011;
-}
+
+open my $fh, '<', $f1;
+is(my $nil = <$fh>, undef, 'FIFO open');
+close $fh;
 ok(-S $sock, 'socket created');
+my $c = IO::Socket::UNIX->new(%o);
 ok($c, 'socket connected');
 is(send($c, 'GET', MSG_NOSIGNAL), 3, 'trickled 3 bytes') or diag "send: $!";