File: check_n_requests2.pm

package info (click to toggle)
libapache2-mod-perl2 2.0.9~1624218-2%2Bdeb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 11,912 kB
  • ctags: 4,588
  • sloc: perl: 95,064; ansic: 14,527; makefile: 49; sh: 18
file content (48 lines) | stat: -rw-r--r-- 1,063 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package TestApache2::check_n_requests2;

use strict;
use warnings;

use Apache2::Const -compile => qw(OK);

use Apache::Test qw(-withtestmore);

use Apache2::SizeLimit;

use constant ONE_MB    => 1024;
use constant TEN_MB    => ONE_MB * 10;
use constant TWENTY_MB => TEN_MB * 2;

my $i = 0;
my %hash = ();

sub handler {
    my $r = shift;

    plan $r, tests => 11;

    Apache2::SizeLimit->add_cleanup_handler($r);
    Apache2::SizeLimit->set_max_process_size(TEN_MB);
    ## this should cause us _NOT_ to fire
    Apache2::SizeLimit->set_check_interval(5);

    # We can assume this will use _at least_ 1MB of memory, based on
    # assuming a scalar consumes >= 1K.
    # and after 10 requests, we should be _at least_ 10MB of memory
    for (0..9) {
        my @big = ('x') x ONE_MB;
        $hash{$i++} = \@big;

        is($i, $i, "now using $i MB of memory (at least)");
    }

    is(
       1,
       Apache2::SizeLimit->_limits_are_exceeded(), 
       "we passed the limits and will _NOT_ kill the child"
      );

    return Apache2::Const::OK;
}

1;