changeset 30:a8e8b7a664c1

Tests: basic fastcgi tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 12 Oct 2008 04:31:08 +0400
parents 71ea39729fa0
children baf9c51d166c
files fastcgi.t
diffstat 1 files changed, 82 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/fastcgi.t
@@ -0,0 +1,82 @@
+#!/usr/bin/perl
+
+# (C) Maxim Dounin
+
+# Test for fastcgi backend.
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+use IO::Select;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+eval { require FCGI; };
+plain(skip_all => 'FCGI not installed') if $@;
+
+my $t = Test::Nginx->new()->plan(3)
+	->write_file_expand('nginx.conf', <<'EOF');
+
+master_process off;
+daemon         off;
+
+events {
+    worker_connections  1024;
+}
+
+http {
+    access_log    off;
+
+    server {
+        listen       localhost:8080;
+        server_name  localhost;
+
+        location / {
+            fastcgi_pass 127.0.0.1:8081;
+        }
+    }
+}
+
+EOF
+
+$t->run_daemon(\&fastcgi_daemon);
+$t->run();
+
+###############################################################################
+
+like(http_get('/'), qr/SEE-THIS/, 'fastcgi request');
+like(http_get('/redir'), qr/302/, 'fastcgi redirect');
+like(http_get('/'), qr/^3$/m, 'fastcgi third request');
+
+###############################################################################
+
+sub fastcgi_daemon {
+	my $socket = FCGI::OpenSocket(':8081', 5);
+	my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
+		$socket);
+
+	my $count;
+	while( $request->Accept() >= 0 ) {
+		print "Location: http://localhost:8080/redirect\r\n";
+		print "Content-type: text/html\r\n";
+		print "\r\n";
+		print "SEE-THIS\n";
+		print ++$count;
+	}
+
+	FCGI::CloseSocket($socket);
+}
+
+###############################################################################