annotate fastcgi_unix.t @ 1248:70192b1baf01

Tests: added exception test to stream_js.t using 'require'. The stream js tests introduced in edf5a3c9e36a fail on njs 0.1.14. It doesn't currently provide an easy way to check its version, whilst we are obligated to gracefully handle such cases somehow. With such an addition of 'require', now the tests are skipped instead on the previous versions.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 21 Nov 2017 13:16:39 +0300
parents 882267679006
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
803
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Maxim Dounin
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Sergey Kandaurov
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # (C) Nginx, Inc.
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 # Test for fastcgi backend with unix socket.
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 ###############################################################################
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use warnings;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use strict;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 use Test::More;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use lib 'lib';
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 eval { require FCGI; };
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 plan(skip_all => 'FCGI not installed') if $@;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 plan(skip_all => 'win32') if $^O eq 'MSWin32';
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 eval { require IO::Socket::UNIX; };
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 plan(skip_all => 'IO::Socket::UNIX not installed') if $@;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 my $t = Test::Nginx->new()->has(qw/http fastcgi unix/)->plan(6)
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 ->write_file_expand('nginx.conf', <<'EOF');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS%%
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 daemon off;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 events {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 http {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 %%TEST_GLOBALS_HTTP%%
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 upstream u {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
47 server 127.0.0.1:8081;
803
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
51 listen 127.0.0.1:8080;
803
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 server_name localhost;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 location / {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 fastcgi_pass unix:%%TESTDIR%%/unix.sock;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 fastcgi_param REQUEST_URI $request_uri;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 location /var {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 fastcgi_pass $arg_b;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 fastcgi_param REQUEST_URI $request_uri;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 EOF
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 my $path = $t->testdir() . '/unix.sock';
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 $t->run_daemon(\&fastcgi_daemon, $path);
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 $t->run();
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 # wait for unix socket to appear
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 for (1 .. 50) {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 last if -S $path;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 select undef, undef, undef, 0.1;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 ###############################################################################
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 like(http_get('/redir'), qr/ 302 /, 'fastcgi redirect');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 like(http_get('/'), qr/^3$/m, 'fastcgi third request');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 unlike(http_head('/'), qr/SEE-THIS/, 'no data in HEAD');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 like(http_get('/stderr'), qr/SEE-THIS/, 'large stderr handled');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 like(http_get("/var?b=unix:$path"), qr/SEE-THIS/, 'fastcgi with variables');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 ###############################################################################
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 sub fastcgi_daemon {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 my $socket = FCGI::OpenSocket(shift, 5);
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 $socket);
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 my $count;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 while( $request->Accept() >= 0 ) {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 $count++;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 if ($ENV{REQUEST_URI} eq '/stderr') {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 warn "sample stderr text" x 512;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 print <<EOF;
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 803
diff changeset
108 Location: http://localhost/redirect
803
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 Content-Type: text/html
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 SEE-THIS
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 $count
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 EOF
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 FCGI::CloseSocket($socket);
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 ###############################################################################