tests: port some bad config tests to Perl 5
[unicorn.git] / t / reload-bad-config.t
blobc7055c7e7846687abb7a006001486757efacc77e
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";
9 my $u_conf = "$tmpdir/u.conf.rb";
11 open my $fh, '>', $ru;
12 print $fh <<'EOM';
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 ] ] }
17 EOM
18 close $fh;
20 open $fh, '>', $u_conf;
21 print $fh <<EOM;
22 preload_app true
23 stderr_path "$err_log"
24 EOM
25 close $fh;
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');
34 open $fh, '>>', $ru;
35 say $fh '....this better be a syntax error in any version of ruby...';
36 close $fh;
38 $ar->do_kill('HUP'); # reload
39 my @l;
40 for (1..1000) {
41         @l = grep(/(?:done|error) reloading/, slurp($err_log)) and
42                 last;
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;
48 close $fh;
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');
56 check_stderr;
57 undef $tmpdir; # quiet t/lib.perl END{}
58 done_testing;