view proxy-store.t @ 107:1c0ec30614c6

Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks. TEST_GLOBALS replaces previously used -g switch. This allows tests to be executed on 0.6.* branch. For compatibility with old tests -g switch will be used if TEST_GLOBALS wasn't expaneded in config. TEST_GLOBALS_HTTP replaces multiple variables (access_log, root, client_body_temp_path, proxy_temp_path, fastcgi_temp_path) previously specified directly in test configs. This change reduce duplication and allows tests to be used with nginx compiled without fastcgi and/or proxy modules (as proxy_temp_path and fastcgi_temp_path are added conditionally).
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 14 Oct 2009 02:23:52 +0400
parents 1d3c82227a05
children 8ac1faaddd2c
line wrap: on
line source

#!/usr/bin/perl

# (C) Maxim Dounin

# Tests for proxy_store functionality.

###############################################################################

use warnings;
use strict;

use Test::More tests => 7;

BEGIN { use FindBin; chdir($FindBin::Bin); }

use lib 'lib';
use Test::Nginx;

###############################################################################

select STDERR; $| = 1;
select STDOUT; $| = 1;

my $t = Test::Nginx->new();

$t->write_file_expand('nginx.conf', <<'EOF');

%%TEST_GLOBALS%%

master_process off;
daemon         off;

events {
}

http {
    %%TEST_GLOBALS_HTTP%%

    server {
        listen       127.0.0.1:8080;
        server_name  localhost;

        location /store- {
            proxy_pass http://127.0.0.1:8080/;
            proxy_store on;
        }
        location /ssi.html {
            ssi on;
        }
        location /index-nostore.html {
            add_header  X-Accel-Expires  0;
        }
        location /index-big.html {
            limit_rate  200k;
        }
    }
}

EOF

$t->write_file('index.html', 'SEE-THIS');
$t->write_file('index-nostore.html', 'SEE-THIS');
$t->write_file('index-big.html', 'x' x (100 << 10));
$t->write_file('ssi.html',
	'<!--#include virtual="/store-index-big.html?1" -->' .
	'<!--#include virtual="/store-index-big.html?2" -->'
);
$t->run();

###############################################################################

like(http_get('/store-index.html'), qr/SEE-THIS/, 'proxy request');
ok(-e $t->testdir() . '/store-index.html', 'result stored');

like(http_get('/store-index-nostore.html'), qr/SEE-THIS/,
	'proxy request with x-accel-expires');

TODO: {
local $TODO = 'patch under review';

ok(!-e $t->testdir() . '/store-index-nostore.html', 'result not stored');
}

ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0, 'no temp files');

http_get('/store-index-big.html', aborted => 1, sleep => 0.1);
sleep(1);

ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0,
	'no temp files after aborted request');

TODO: {
local $TODO = 'not fixed yet';

http_get('/ssi.html', aborted => 1, sleep => 0.1);
sleep(1);

ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0,
	'no temp files after aborted ssi');

}

###############################################################################