comparison perl_sleep.t @ 1159:a0324ac9addc

Tests: perl $r->sleep tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 02 Apr 2017 17:08:19 +0300
parents
children 766bcbb632ee
comparison
equal deleted inserted replaced
1158:3a3a7f68c6d7 1159:a0324ac9addc
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for embedded perl module, $r->sleep().
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
15
16 use lib 'lib';
17 use Test::Nginx;
18
19 ###############################################################################
20
21 select STDERR; $| = 1;
22 select STDOUT; $| = 1;
23
24 my $t = Test::Nginx->new()->has(qw/http perl ssi/)->plan(2)
25 ->write_file_expand('nginx.conf', <<'EOF');
26
27 %%TEST_GLOBALS%%
28
29 daemon off;
30
31 events {
32 }
33
34 http {
35 %%TEST_GLOBALS_HTTP%%
36
37 server {
38 listen 127.0.0.1:8080;
39 server_name localhost;
40
41 location / {
42 ssi on;
43 sendfile_max_chunk 100;
44 postpone_output 0;
45 }
46
47 location /sleep {
48 perl 'sub {
49 my $r = shift;
50
51 $r->sleep(100, sub {
52 my $r = shift;
53 $r->send_http_header;
54 $r->print("it works");
55 return OK;
56 });
57
58 return OK;
59 }';
60 }
61 }
62 }
63
64 EOF
65
66 $t->write_file('subrequest.html', ('x' x 200) .
67 'X<!--#include virtual="/sleep" -->X');
68
69 $t->run();
70
71 ###############################################################################
72
73 like(http_get('/sleep'), qr/works/, 'perl sleep');
74
75 TODO: {
76 local $TODO = 'not yet' unless $t->has_version('1.11.13');
77
78 like(http_get('/subrequest.html'), qr/works/, 'perl sleep in subrequest');
79
80 }
81
82 ###############################################################################