2 # Copyright (C) unicorn hackers <unicorn-public@yhbt.net>
3 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4 use v5.14; BEGIN { require './t/lib.perl' };
6 my $srv = tcp_server();
7 my $host_port = tcp_host_port($srv);
8 my $ru = "$tmpdir/config.ru";
9 my $u_conf = "$tmpdir/u.conf.rb";
11 open my $fh, '>', $ru;
13 use Rack::ContentLength
14 use Rack::ContentType, 'text/plain'
15 config = ru = "hello world\n" # check for config variable conflicts, too
16 run lambda { |env| [ 200, {}, [ ru.to_s ] ] }
20 open $fh, '>', $u_conf;
23 stderr_path "$err_log"
27 my $ar = unicorn(qw(-E none -c), $u_conf, $ru, { 3 => $srv });
28 my $c = tcp_start($srv, 'GET / HTTP/1.0');
29 my ($status, $hdr) = slurp_hdr($c);
30 my $bdy = do { local $/; <$c> };
31 like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid at start');
32 is($bdy, "hello world\n", 'body matches expected');
35 say $fh '....this better be a syntax error in any version of ruby...';
38 $ar->do_kill('HUP'); # reload
41 @l = grep(/(?:done|error) reloading/, slurp($err_log)) and
43 select undef, undef, undef, 0.011;
45 diag slurp($err_log) if $ENV{V};
46 ok(grep(/error reloading/, @l), 'got error reloading');
47 open $fh, '>', $err_log;
50 $c = tcp_start($srv, 'GET / HTTP/1.0');
51 ($status, $hdr) = slurp_hdr($c);
52 $bdy = do { local $/; <$c> };
53 like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid afte reload');
54 is($bdy, "hello world\n", 'body matches expected after reload');
57 undef $tmpdir; # quiet t/lib.perl END{}