annotate geo_unix.t @ 1982:fb25cbe9d4ec default tip

Tests: explicit Valgrind support. Valgrind logging is done to a separate file, as it is not able to follow stderr redirection within nginx or append to a file without corrupting it. Further, Valgrind logging seems to interfere with error suppression in tests, and catches various startup errors and warnings, so the log is additionally filtered. Since startup under Valgrind can be really slow, timeout in waitforfile() was changed to 10 seconds. Prodded by Robert Mueller.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 31 May 2024 06:23:00 +0300
parents 5ac6efbe5552
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1418
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for http geo module with unix socket.
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
1573
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1535
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http geo proxy unix/)->plan(6);
1418
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 $t->write_file_expand('nginx.conf', <<'EOF');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 daemon off;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 events {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 http {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 geo $geo {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 default default;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 255.255.255.255 none;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 geo $remote_addr $geora {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 default default;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 255.255.255.255 none;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 geo $geor {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 ranges;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 0.0.0.0-255.255.255.254 test;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 default none;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 geo $remote_addr $georra {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 ranges;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 0.0.0.0-255.255.255.254 test;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 default none;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 geo $arg_ip $geo_arg {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 default default;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 192.0.2.0/24 test;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 server {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 listen unix:%%TESTDIR%%/unix.sock;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 server_name localhost;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 location / {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 add_header X-Geo $geo;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 add_header X-Addr $geora;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 add_header X-Ranges $geor;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 add_header X-Ranges-Addr $georra;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 add_header X-Arg $geo_arg;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 server {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 listen 127.0.0.1:8080;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 location / {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 proxy_pass http://unix:%%TESTDIR%%/unix.sock;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 EOF
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 $t->write_file('index.html', '');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 $t->run();
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 ###############################################################################
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 my $r = http_get('/');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 like($r, qr/^X-Geo: none/m, 'geo unix');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 like($r, qr/^X-Ranges: none/m, 'geo unix ranges');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 like($r, qr/^X-Addr: none/m, 'geo unix remote addr');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 like($r, qr/^X-Ranges-Addr: none/m, 'geo unix ranges remote addr');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 like(http_get('/?ip=192.0.2.1'), qr/^X-Arg: test/m, 'geo unix variable');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
1573
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1535
diff changeset
103 $t->stop();
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1535
diff changeset
104
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1535
diff changeset
105 is(-e $t->testdir() . '/unix.sock', undef, 'unix socket removed');
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1535
diff changeset
106
1418
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 ###############################################################################