From 43c7d73b8b9e6995b5a986b10a8623395e89a538 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 5 Jun 2023 10:12:39 +0000 Subject: [PATCH 10/23] port t0019-max_header_len.sh to Perl 5 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. --- GNUmakefile | 2 +- t/README | 7 +----- t/integration.ru | 1 + t/integration.t | 43 +++++++++++++++++++++++++++++++--- t/t0019-max_header_len.sh | 49 --------------------------------------- 5 files changed, 43 insertions(+), 59 deletions(-) delete mode 100755 t/t0019-max_header_len.sh diff --git a/GNUmakefile b/GNUmakefile index 5cca189..eab9082 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -125,7 +125,7 @@ $(T_sh): dep $(test_prereq) t/random_blob t/trash/.gitignore t/trash/.gitignore : | t/trash echo '*' >$@ -dependencies := socat curl +dependencies := curl deps := $(addprefix t/.dep+,$(dependencies)) $(deps): dep_bin = $(lastword $(subst +, ,$@)) $(deps): 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 @@ def rack_input_tests(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 # License: GPL-3.0+ -# 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 <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