unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob c023b88c4917649eb16c210fa08c4e89e9c5314f 1526 bytes (raw)
$ git show HEAD:t/reload-bad-config.t	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
#!perl -w
# Copyright (C) unicorn hackers <unicorn-public@yhbt.net>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
use v5.14; BEGIN { require './t/lib.perl' };
use autodie;
my $srv = tcp_server();
my $host_port = tcp_host_port($srv);
my $ru = "$tmpdir/config.ru";
my $u_conf = "$tmpdir/u.conf.rb";

open my $fh, '>', $ru;
print $fh <<'EOM';
use Rack::ContentLength
use Rack::ContentType, 'text/plain'
config = ru = "hello world\n" # check for config variable conflicts, too
run lambda { |env| [ 200, {}, [ ru.to_s ] ] }
EOM
close $fh;

open $fh, '>', $u_conf;
print $fh <<EOM;
preload_app true
stderr_path "$err_log"
EOM
close $fh;

my $ar = unicorn(qw(-E none -c), $u_conf, $ru, { 3 => $srv });
my ($status, $hdr, $bdy) = do_req($srv, 'GET / HTTP/1.0');
like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid at start');
is($bdy, "hello world\n", 'body matches expected');

open $fh, '>>', $ru;
say $fh '....this better be a syntax error in any version of ruby...';
close $fh;

$ar->do_kill('HUP'); # reload
my @l;
for (1..1000) {
	@l = grep(/(?:done|error) reloading/, slurp($err_log)) and
		last;
	sleep 0.011;
}
diag slurp($err_log) if $ENV{V};
ok(grep(/error reloading/, @l), 'got error reloading');
open $fh, '>', $err_log;
close $fh;

($status, $hdr, $bdy) = do_req($srv, 'GET / HTTP/1.0');
like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid afte reload');
is($bdy, "hello world\n", 'body matches expected after reload');

check_stderr;
undef $tmpdir; # quiet t/lib.perl END{}
done_testing;

git clone https://yhbt.net/unicorn.git