diff options
author | Eric Wong <BOFH@YHBT.net> | 2023-06-05 10:12:32 +0000 |
---|---|---|
committer | Eric Wong <bofh@yhbt.net> | 2023-06-05 10:38:36 +0000 |
commit | 7544ccba6d6b9f388b7a88a0a54a8a95616f0eae (patch) | |
tree | ab158b850ae608bae5913528de1d1f624b24d73a | |
parent | 8ae028f9ef9c8306a07a01e9045e8881cadf780f (diff) | |
download | unicorn-7544ccba6d6b9f388b7a88a0a54a8a95616f0eae.tar.gz |
This doesn't require restarting, so it's a perfect candidate.
-rw-r--r-- | t/integration.ru | 15 | ||||
-rw-r--r-- | t/integration.t | 14 | ||||
-rw-r--r-- | t/lib.perl | 2 | ||||
-rwxr-xr-x | t/t0018-write-on-close.sh | 23 | ||||
-rw-r--r-- | t/write-on-close.ru | 11 |
5 files changed, 29 insertions, 36 deletions
diff --git a/t/integration.ru b/t/integration.ru index 5183217..12f5d48 100644 --- a/t/integration.ru +++ b/t/integration.ru @@ -18,6 +18,20 @@ def restore_status_code [ 200, {}, [] ] end +class WriteOnClose + def each(&block) + @callback = block + end + + def close + @callback.call "7\r\nGoodbye\r\n0\r\n\r\n" + end +end + +def write_on_close + [ 200, { 'transfer-encoding' => 'chunked' }, WriteOnClose.new ] +end + run(lambda do |env| case env['REQUEST_METHOD'] when 'GET' @@ -26,6 +40,7 @@ run(lambda do |env| when '/rack-3-array-headers'; [ 200, { 'x-r3' => %w(a b c) }, [] ] when '/nil-header-value'; [ 200, { 'X-Nil' => nil }, [] ] when '/unknown-status-pass-through'; [ '666 I AM THE BEAST', {}, [] ] + when '/write_on_close'; write_on_close end # case PATH_INFO (GET) when 'POST' case env['PATH_INFO'] diff --git a/t/integration.t b/t/integration.t index e876c71..3ab5c90 100644 --- a/t/integration.t +++ b/t/integration.t @@ -4,6 +4,7 @@ use v5.14; BEGIN { require './t/lib.perl' }; 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 }); @@ -66,8 +67,19 @@ if ('TODO: ensure Rack::Utils::HTTP_STATUS_CODES is available') { is($status, $orig_200_status, 'original status restored'); } +SKIP: { + eval { require HTTP::Tiny } or skip "HTTP::Tiny missing: $@", 1; + my $ht = HTTP::Tiny->new; + my $res = $ht->get("http://$host_port/write_on_close"); + is($res->{content}, 'Goodbye', 'write-on-close body read'); +} # ... more stuff here undef $ar; -diag slurp("$tmpdir/err.log") if $ENV{V}; +my @log = slurp("$tmpdir/err.log"); +diag("@log") if $ENV{V}; +my @err = grep(!/NameError.*Unicorn::Waiter/, grep(/error/i, @log)); +is_deeply(\@err, [], 'no unexpected errors in stderr'); +is_deeply([grep(/SIGKILL/, @log)], [], 'no SIGKILL in stderr'); + done_testing; @@ -10,7 +10,7 @@ use POSIX qw(dup2 _exit setpgid :signal_h SEEK_SET F_SETFD); use File::Temp 0.19 (); # 0.19 for ->newdir our ($tmpdir, $errfh); our @EXPORT = qw(unicorn slurp tcp_server tcp_connect unicorn $tmpdir $errfh - SEEK_SET); + SEEK_SET tcp_host_port); my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!); $tmpdir = File::Temp->newdir("unicorn-$base-XXXX", TMPDIR => 1); diff --git a/t/t0018-write-on-close.sh b/t/t0018-write-on-close.sh deleted file mode 100755 index 3afefea..0000000 --- a/t/t0018-write-on-close.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -. ./test-lib.sh -t_plan 4 "write-on-close tests for funky response-bodies" - -t_begin "setup and start" && { - unicorn_setup - unicorn -D -c $unicorn_config write-on-close.ru - unicorn_wait_start -} - -t_begin "write-on-close response body succeeds" && { - test xGoodbye = x"$(curl -sSf http://$listen/)" -} - -t_begin "killing succeeds" && { - kill $unicorn_pid -} - -t_begin "check stderr" && { - check_stderr -} - -t_done diff --git a/t/write-on-close.ru b/t/write-on-close.ru deleted file mode 100644 index 725c4d6..0000000 --- a/t/write-on-close.ru +++ /dev/null @@ -1,11 +0,0 @@ -class WriteOnClose - def each(&block) - @callback = block - end - - def close - @callback.call "7\r\nGoodbye\r\n0\r\n\r\n" - end -end -use Rack::ContentType, "text/plain" -run(lambda { |_| [ 200, { 'transfer-encoding' => 'chunked' }, WriteOnClose.new ] }) |