unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
blob 3067f284bbb5b0a28bf62a114955b86c560e74b5 2756 bytes (raw)
name: t/client_body_buffer_size.t 	 # note: path name is non-authoritative(*)

 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 
#!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 $uconf = "$tmpdir/u.conf.rb";

open my $conf_fh, '>', $uconf;
$conf_fh->autoflush(1);
print $conf_fh <<EOM;
client_body_buffer_size 0
EOM
my $srv = tcp_server();
my $host_port = tcp_host_port($srv);
my @uarg = (qw(-E none t/client_body_buffer_size.ru -c), $uconf);
my $ar = unicorn(@uarg, { 3 => $srv });
my ($c, $status, $hdr);
my $mem_class = 'StringIO';
my $fs_class = 'Unicorn::TmpIO';

$c = tcp_start($srv, "PUT /input_class HTTP/1.0\r\nContent-Length: 0");
($status, $hdr) = slurp_hdr($c);
like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid');
is(readline($c), $mem_class, 'zero-byte file is StringIO');

$c = tcp_start($srv, "PUT /tmp_class HTTP/1.0\r\nContent-Length: 1");
print $c '.';
($status, $hdr) = slurp_hdr($c);
like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid');
is(readline($c), $fs_class, '1 byte file is filesystem-backed');


my $fifo = "$tmpdir/fifo";
POSIX::mkfifo($fifo, 0600) or die "mkfifo: $!";
seek($conf_fh, 0, SEEK_SET);
truncate($conf_fh, 0);
print $conf_fh <<EOM;
after_fork { |_,_| File.open('$fifo', 'w') { |fp| fp.write "pid=#\$\$" } }
EOM
$ar->do_kill('HUP');
open my $fifo_fh, '<', $fifo;
like(my $wpid = readline($fifo_fh), qr/\Apid=\d+\z/a ,
	'reloaded w/ default client_body_buffer_size');


$c = tcp_start($srv, "PUT /tmp_class HTTP/1.0\r\nContent-Length: 1");
($status, $hdr) = slurp_hdr($c);
like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid');
is(readline($c), $mem_class, 'class for a 1 byte file is memory-backed');


my $one_meg = 1024 ** 2;
$c = tcp_start($srv, "PUT /tmp_class HTTP/1.0\r\nContent-Length: $one_meg");
($status, $hdr) = slurp_hdr($c);
like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid');
is(readline($c), $fs_class, '1 megabyte file is FS-backed');

# reload with bigger client_body_buffer_size
say $conf_fh "client_body_buffer_size $one_meg";
$ar->do_kill('HUP');
open $fifo_fh, '<', $fifo;
like($wpid = readline($fifo_fh), qr/\Apid=\d+\z/a ,
	'reloaded w/ bigger client_body_buffer_size');


$c = tcp_start($srv, "PUT /tmp_class HTTP/1.0\r\nContent-Length: $one_meg");
($status, $hdr) = slurp_hdr($c);
like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid');
is(readline($c), $mem_class, '1 megabyte file is now memory-backed');

my $too_big = $one_meg + 1;
$c = tcp_start($srv, "PUT /tmp_class HTTP/1.0\r\nContent-Length: $too_big");
($status, $hdr) = slurp_hdr($c);
like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid');
is(readline($c), $fs_class, '1 megabyte + 1 byte file is FS-backed');


undef $ar;
check_stderr;
undef $tmpdir;
done_testing;

debug log:

solving 3067f28 ...
found 3067f28 in https://yhbt.net/unicorn.git/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).