port test/unit/test_ccc.rb to Perl 5
[unicorn.git] / t / reload-bad-config.t
blob4c179683b89a75c20b7f9a2ce8536c1949c7d42c
1 #!perl -w
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' };
5 use autodie;
6 my $srv = tcp_server();
7 my $host_port = tcp_host_port($srv);
8 my $ru = "$tmpdir/config.ru";
10 write_file '>', $ru, <<'EOM';
11 use Rack::ContentLength
12 use Rack::ContentType, 'text/plain'
13 config = ru = "hello world\n" # check for config variable conflicts, too
14 run lambda { |env| [ 200, {}, [ ru.to_s ] ] }
15 EOM
17 write_file '>', $u_conf, <<EOM;
18 preload_app true
19 stderr_path "$err_log"
20 EOM
22 my $ar = unicorn(qw(-E none -c), $u_conf, $ru, { 3 => $srv });
23 my ($status, $hdr, $bdy) = do_req($srv, 'GET / HTTP/1.0');
24 like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid at start');
25 is($bdy, "hello world\n", 'body matches expected');
27 write_file '>>', $ru, <<'EOM';
28 ....this better be a syntax error in any version of ruby...
29 EOM
31 $ar->do_kill('HUP'); # reload
32 my @l;
33 for (1..1000) {
34         @l = grep(/(?:done|error) reloading/, slurp($err_log)) and
35                 last;
36         sleep 0.011;
38 diag slurp($err_log) if $ENV{V};
39 ok(grep(/error reloading/, @l), 'got error reloading');
40 open my $fh, '>', $err_log; # truncate
41 close $fh;
43 ($status, $hdr, $bdy) = do_req($srv, 'GET / HTTP/1.0');
44 like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid afte reload');
45 is($bdy, "hello world\n", 'body matches expected after reload');
47 check_stderr;
48 undef $tmpdir; # quiet t/lib.perl END{}
49 done_testing;