about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <BOFH@YHBT.net>2023-06-05 10:12:39 +0000
committerEric Wong <bofh@yhbt.net>2023-06-05 10:38:46 +0000
commit96e404860c35860d30faf08bb16c2d5242f5697c (patch)
tree559995ad2367d195d50b77790f9089aa5b5e298e /t
parentd97e74049f4e989d3061234b1b9cd5f50e7acdd9 (diff)
downloadunicorn-96e404860c35860d30faf08bb16c2d5242f5697c.tar.gz
This was the final socat requirement for integration tests.
I think curl will remain an optional dependency for tests
since it's probably the most widely-installed HTTP client.
Diffstat (limited to 't')
-rw-r--r--t/README7
-rw-r--r--t/integration.ru1
-rw-r--r--t/integration.t43
-rwxr-xr-xt/t0019-max_header_len.sh49
4 files changed, 42 insertions, 58 deletions
diff --git a/t/README b/t/README
index 8a5243e..d09c715 100644
--- a/t/README
+++ b/t/README
@@ -10,18 +10,13 @@ to test real-world behavior and Ruby introduces incompatibilities
 at a far faster rate than Perl 5.  Perl is Ruby's older cousin, so
 it should be easy-to-learn for Rubyists.
 
-Old tests are in Bourne shell, but the socat(1) dependency was probably
-too rare compared to Perl 5.
+Old tests are in Bourne shell and slowly being ported to Perl 5.
 
 == Requirements
 
 * {Ruby 2.0.0+}[https://www.ruby-lang.org/en/]
 * {Perl 5.14+}[https://www.perl.org/] # your distro should have it
 * {GNU make}[https://www.gnu.org/software/make/]
-
-The following requirements will eventually be dropped.
-
-* {socat}[http://www.dest-unreach.org/socat/]
 * {curl}[https://curl.haxx.se/]
 
 We do not use bashisms or any non-portable, non-POSIX constructs
diff --git a/t/integration.ru b/t/integration.ru
index 98528f6..edc408c 100644
--- a/t/integration.ru
+++ b/t/integration.ru
@@ -81,6 +81,7 @@ run(lambda do |env|
     when '/env_dump'; [ 200, {}, [ env_dump(env) ] ]
     when '/write_on_close'; write_on_close
     when '/pid'; [ 200, {}, [ "#$$\n" ] ]
+    else '/'; [ 200, {}, [ env_dump(env) ] ]
     end # case PATH_INFO (GET)
   when 'POST'
     case env['PATH_INFO']
diff --git a/t/integration.t b/t/integration.t
index af17d51..c687655 100644
--- a/t/integration.t
+++ b/t/integration.t
@@ -1,15 +1,19 @@
 #!perl -w
 # Copyright (C) unicorn hackers <unicorn-public@yhbt.net>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
-# this is the main integration test for things which don't require
-# restarting or signals
+
+# This is the main integration test for fast-ish things to minimize
+# Ruby startup time penalties.
 
 use v5.14; BEGIN { require './t/lib.perl' };
 use autodie;
 my $srv = tcp_server();
 my $host_port = tcp_host_port($srv);
 my $t0 = time;
-my $ar = unicorn(qw(-E none t/integration.ru), { 3 => $srv });
+my $conf = "$tmpdir/u.conf.rb";
+open my $conf_fh, '>', $conf;
+$conf_fh->autoflush(1);
+my $ar = unicorn(qw(-E none t/integration.ru -c), $conf, { 3 => $srv });
 my $curl = which('curl');
 END { diag slurp("$tmpdir/err.log") if $tmpdir };
 sub slurp_hdr {
@@ -207,7 +211,40 @@ SKIP: {
         $do_curl->('-T-');
 }
 
+
 # ... more stuff here
+
+# SIGHUP-able stuff goes here
+
+if ('max_header_len internal API') {
+        undef $c;
+        my $req = 'GET / HTTP/1.0';
+        my $len = length($req."\r\n\r\n");
+        my $fifo = "$tmpdir/fifo";
+        POSIX::mkfifo($fifo, 0600) or die "mkfifo: $!";
+        print $conf_fh <<EOM;
+Unicorn::HttpParser.max_header_len = $len
+listen "$host_port" # TODO: remove this requirement for SIGHUP
+after_fork { |_,_| File.open('$fifo', 'w') { |fp| fp.write "pid=#\$\$" } }
+EOM
+        $ar->do_kill('HUP');
+        open my $fifo_fh, '<', $fifo;
+        my $wpid = readline($fifo_fh);
+        like($wpid, qr/\Apid=\d+\z/a , 'new worker ready');
+        close $fifo_fh;
+        $wpid =~ s/\Apid=// or die;
+        ok(CORE::kill(0, $wpid), 'worker PID retrieved');
+
+        $c = start_req($srv, $req);
+        ($status, $hdr) = slurp_hdr($c);
+        like($status, qr!\AHTTP/1\.[01] 200\b!, 'minimal request succeeds');
+
+        $c = start_req($srv, 'GET /xxxxxx HTTP/1.0');
+        ($status, $hdr) = slurp_hdr($c);
+        like($status, qr!\AHTTP/1\.[01] 413\b!, 'big request fails');
+}
+
+
 undef $ar;
 my @log = slurp("$tmpdir/err.log");
 diag("@log") if $ENV{V};
diff --git a/t/t0019-max_header_len.sh b/t/t0019-max_header_len.sh
deleted file mode 100755
index 6a355b4..0000000
--- a/t/t0019-max_header_len.sh
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/sh
-. ./test-lib.sh
-t_plan 5 "max_header_len setting (only intended for Rainbows!)"
-
-t_begin "setup and start" && {
-        unicorn_setup
-        req='GET / HTTP/1.0\r\n\r\n'
-        len=$(printf "$req" | count_bytes)
-        echo Unicorn::HttpParser.max_header_len = $len >> $unicorn_config
-        unicorn -D -c $unicorn_config env.ru
-        unicorn_wait_start
-}
-
-t_begin "minimal request succeeds" && {
-        rm -f $tmp
-        (
-                cat $fifo > $tmp &
-                printf "$req"
-                wait
-                echo ok > $ok
-        ) | socat - TCP:$listen > $fifo
-        test xok = x$(cat $ok)
-
-        fgrep "HTTP/1.1 200 OK" $tmp
-}
-
-t_begin "big request fails" && {
-        rm -f $tmp
-        (
-                cat $fifo > $tmp &
-                printf 'GET /xxxxxx HTTP/1.0\r\n\r\n'
-                wait
-                echo ok > $ok
-        ) | socat - TCP:$listen > $fifo
-        test xok = x$(cat $ok)
-        fgrep "HTTP/1.1 413" $tmp
-}
-
-dbgcat tmp
-
-t_begin "killing succeeds" && {
-        kill $unicorn_pid
-}
-
-t_begin "check stderr" && {
-        check_stderr
-}
-
-t_done