annotate stream_tcp_nodelay.t @ 1585:bff287fbf347

Tests: added proxy_cookie_domain/path tests with "off" parameter.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 23 Jul 2020 12:17:39 +0300
parents 196d33c2bb45
children f3ba4c74de31
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Andrey Zelenkov
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Sergey Kandaurov
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # (C) Nginx, Inc.
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 # Stream tests for tcp_nodelay.
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 ###############################################################################
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use warnings;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use strict;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 use Test::More;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 use IO::Select;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 BEGIN { use FindBin; chdir($FindBin::Bin); }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use lib 'lib';
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 use Test::Nginx;
816
77359b849cd5 Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 812
diff changeset
22 use Test::Nginx::Stream qw/ stream /;
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 ###############################################################################
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 select STDERR; $| = 1;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 select STDOUT; $| = 1;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 my $t = Test::Nginx->new()->has(qw/stream/);
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 $t->plan(2)->write_file_expand('nginx.conf', <<'EOF');
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 %%TEST_GLOBALS%%
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 daemon off;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 events {
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 stream {
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 proxy_buffer_size 1;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 tcp_nodelay off;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
45 listen 127.0.0.1:8081;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
46 proxy_pass 127.0.0.1:8080;
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 server {
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 tcp_nodelay on;
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
51 listen 127.0.0.1:8082;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
52 proxy_pass 127.0.0.1:8080;
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 EOF
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 $t->run_daemon(\&stream_daemon);
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
59 $t->run()->waitforsocket('127.0.0.1:' . port(8080));
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 ###############################################################################
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
812
acec03d44976 Tests: close connection on last write in stream_tcp_nodelay.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 711
diff changeset
63 my $str = '1234567890' x 10 . 'F';
816
77359b849cd5 Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 812
diff changeset
64 my $length = length($str);
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
66 is(stream('127.0.0.1:' . port(8081))->io($str, length => $length), $str,
816
77359b849cd5 Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 812
diff changeset
67 'tcp_nodelay off');
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
68 is(stream('127.0.0.1:' . port(8082))->io($str, length => $length), $str,
816
77359b849cd5 Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 812
diff changeset
69 'tcp_nodelay on');
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 ###############################################################################
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 sub stream_daemon {
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 my $server = IO::Socket::INET->new(
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 Proto => 'tcp',
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
76 LocalAddr => '127.0.0.1:' . port(8080),
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 Listen => 5,
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 Reuse => 1
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 )
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 or die "Can't create listening socket: $!\n";
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 my $sel = IO::Select->new($server);
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 local $SIG{PIPE} = 'IGNORE';
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 while (my @ready = $sel->can_read) {
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 foreach my $fh (@ready) {
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 if ($server == $fh) {
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 my $new = $fh->accept;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 $new->autoflush(1);
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 $sel->add($new);
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 } elsif (stream_handle_client($fh)) {
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 $sel->remove($fh);
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 $fh->close;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 sub stream_handle_client {
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 my ($client) = @_;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 log2c("(new connection $client)");
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 $client->sysread(my $buffer, 65536) or return 1;
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 log2i("$client $buffer");
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109
812
acec03d44976 Tests: close connection on last write in stream_tcp_nodelay.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 711
diff changeset
110 my $close = $buffer =~ /F/;
acec03d44976 Tests: close connection on last write in stream_tcp_nodelay.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 711
diff changeset
111
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 log2o("$client $buffer");
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 $client->syswrite($buffer);
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
812
acec03d44976 Tests: close connection on last write in stream_tcp_nodelay.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 711
diff changeset
116 return $close;
642
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 sub log2i { Test::Nginx::log_core('|| <<', @_); }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 sub log2o { Test::Nginx::log_core('|| >>', @_); }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 sub log2c { Test::Nginx::log_core('||', @_); }
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122
555e718a70a5 Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 ###############################################################################