root/lang/perl/App-Benchmark-WAF/trunk/lib/App/Benchmark/WAF.pm @ 23681

Revision 23681, 1.5 kB (checked in by hidek, 5 years ago)

post test support

  • Property svn:keywords set to Id
Line 
1package App::Benchmark::WAF;
2use strict;
3use warnings;
4use base qw(Exporter);
5use Apache::TestConfig;
6use Apache::TestUtil qw(t_debug);
7use File::Spec;
8use IPC::Open3;
9use Test::More;
10use URI;
11our $VERSION = '0.00001';
12
13our @EXPORT = qw(waf_benchmark_diag);
14our $AB;
15BEGIN {
16    require File::Spec->catfile('t', 'conf', 'apache_test_config.pm');
17    my $config = apache_test_config->new();
18    $AB = $ENV{APACHE_BENCH} ||
19        File::Spec->catfile($config->{vars}->{bindir}, "ab");
20
21    if (! -x $AB) {
22        plan(skip_all => "could not find a working $AB");
23    } else {
24        plan('no_plan');
25    }
26}
27
28sub waf_benchmark_diag {
29    my %args   = @_;
30
31    my $mode = $args{mode};
32    my $type = $args{type};
33
34    my $config = apache_test_config->new();
35    my $uri = URI->new();
36    $uri->scheme('http');
37    $uri->host( $config->our_remote_addr() );
38    $uri->port( $config->port );
39    $uri->path( $args{path} || join('/', $mode, $type, 'index.cgi' ) );
40
41    my $post = $args{post}
42        ? "-p $args{post} -T \"application/x-www-form-urlencoded\"" : '';
43    my @cmd = ($AB, "-c", $args{concurrency} || 100, "-n", $args{requests} || 1000, $post, '-v 2', $uri);
44   
45    t_debug("running $type in $mode ($uri)");
46    t_debug("command: @cmd");
47
48    # capture output...
49    {
50        my ($stdout, $stdin, $stderr);
51        open3( $stdin, $stdout, $stderr, "@cmd" );
52        while (<$stdout>) {
53            t_debug($_);
54            warn $_;
55            next unless /Requests per second:\s*(.*)$/;
56            diag("[$type ($mode)]: $1");
57        }
58    }
59    ok(1);
60}
61
621;
Note: See TracBrowser for help on using the browser.