comparison fastcgi_unix.t @ 803:aa74b2903227

Tests: basic fastcgi tests with unix socket.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 09 Dec 2015 19:00:43 +0300
parents
children e9064d691790
comparison
equal deleted inserted replaced
802:eca9b1d19021 803:aa74b2903227
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4 # (C) Sergey Kandaurov
5 # (C) Nginx, Inc.
6
7 # Test for fastcgi backend with unix socket.
8
9 ###############################################################################
10
11 use warnings;
12 use strict;
13
14 use Test::More;
15
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
17
18 use lib 'lib';
19 use Test::Nginx;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 eval { require FCGI; };
27 plan(skip_all => 'FCGI not installed') if $@;
28 plan(skip_all => 'win32') if $^O eq 'MSWin32';
29
30 eval { require IO::Socket::UNIX; };
31 plan(skip_all => 'IO::Socket::UNIX not installed') if $@;
32
33 my $t = Test::Nginx->new()->has(qw/http fastcgi unix/)->plan(6)
34 ->write_file_expand('nginx.conf', <<'EOF');
35
36 %%TEST_GLOBALS%%
37
38 daemon off;
39
40 events {
41 }
42
43 http {
44 %%TEST_GLOBALS_HTTP%%
45
46 upstream u {
47 server 127.0.0.1:8081;
48 }
49
50 server {
51 listen 127.0.0.1:8080;
52 server_name localhost;
53
54 location / {
55 fastcgi_pass unix:%%TESTDIR%%/unix.sock;
56 fastcgi_param REQUEST_URI $request_uri;
57 }
58
59 location /var {
60 fastcgi_pass $arg_b;
61 fastcgi_param REQUEST_URI $request_uri;
62 }
63 }
64 }
65
66 EOF
67
68 my $path = $t->testdir() . '/unix.sock';
69
70 $t->run_daemon(\&fastcgi_daemon, $path);
71 $t->run();
72
73 # wait for unix socket to appear
74
75 for (1 .. 50) {
76 last if -S $path;
77 select undef, undef, undef, 0.1;
78 }
79
80 ###############################################################################
81
82 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request');
83 like(http_get('/redir'), qr/ 302 /, 'fastcgi redirect');
84 like(http_get('/'), qr/^3$/m, 'fastcgi third request');
85
86 unlike(http_head('/'), qr/SEE-THIS/, 'no data in HEAD');
87
88 like(http_get('/stderr'), qr/SEE-THIS/, 'large stderr handled');
89
90 like(http_get("/var?b=unix:$path"), qr/SEE-THIS/, 'fastcgi with variables');
91
92 ###############################################################################
93
94 sub fastcgi_daemon {
95 my $socket = FCGI::OpenSocket(shift, 5);
96 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
97 $socket);
98
99 my $count;
100 while( $request->Accept() >= 0 ) {
101 $count++;
102
103 if ($ENV{REQUEST_URI} eq '/stderr') {
104 warn "sample stderr text" x 512;
105 }
106
107 print <<EOF;
108 Location: http://127.0.0.1:8080/redirect
109 Content-Type: text/html
110
111 SEE-THIS
112 $count
113 EOF
114 }
115
116 FCGI::CloseSocket($socket);
117 }
118
119 ###############################################################################