comparison http_listen_wildcard.t @ 1817:c045fbb98e9a

Tests: revised tests for listen port ranges. Renumbered testing ports to get more chance to execute when run in parallel. Relaxed condition to skip tests only when the port range is out of sequence. Adjacent port numbers out of a specified range aren't crucial to skip tests: if not in sequence, statistically this will be caught in subsequent runs. Unsafe tests that use wildcard addresses are moved to a separate file.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 23 Dec 2022 19:20:50 +0400
parents http_listen.t@144c6ce732e4
children
comparison
equal deleted inserted replaced
1816:5817625792bd 1817:c045fbb98e9a
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for listen port ranges with a wildcard address.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/);
26
27 plan(skip_all => 'listen on wildcard address')
28 unless $ENV{TEST_NGINX_UNSAFE};
29
30 $t->write_file_expand('nginx.conf', <<'EOF');
31
32 %%TEST_GLOBALS%%
33
34 daemon off;
35
36 events {
37 }
38
39 http {
40 %%TEST_GLOBALS_HTTP%%
41
42 server {
43 listen 127.0.0.1:8080;
44 listen %%PORT_8186%%-%%PORT_8187%%;
45 server_name localhost;
46
47 location / {
48 proxy_pass http://$arg_b/t;
49 }
50
51 location /t {
52 return 200 $server_addr:$server_port;
53 }
54 }
55
56 # catch out of range
57
58 server {
59 listen 127.0.0.1:8185;
60 listen 127.0.0.1:8188;
61 server_name localhost;
62 }
63 }
64
65 EOF
66
67 my $p5 = port(8185); my $p7 = port(8187);
68 my $p6 = port(8186); my $p8 = port(8188);
69
70 plan(skip_all => 'no requested ranges')
71 if "$p6$p7" ne "81868187";
72
73 $t->run()->plan(4);
74
75 ###############################################################################
76
77 unlike(http_get("/?b=127.0.0.1:$p5"), qr/127.0.0.1:$p5/, 'out of range 1');
78 like(http_get("/?b=127.0.0.1:$p6"), qr/127.0.0.1:$p6/, 'wildcard range 1');
79 like(http_get("/?b=127.0.0.1:$p7"), qr/127.0.0.1:$p7/, 'wildcard range 2');
80 unlike(http_get("/?b=127.0.0.1:$p8"), qr/127.0.0.1:$p8/, 'out of range 2');
81
82 ###############################################################################