httpd-test-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From do...@apache.org
Subject cvs commit: httpd-test/perl-framework/t/http11 post.t
Date Tue, 02 Apr 2002 04:08:33 GMT
dougm       02/04/01 20:08:33

  Modified:    perl-framework/Apache-Test/lib/Apache TestCommon.pm
               perl-framework/t/http11 post.t
  Added:       perl-framework/Apache-Test/lib/Apache TestCommonPost.pm
  Log:
  moving logic from http11/post.t to generic functions that can be called from multiple tests
  
  Revision  Changes    Path
  1.3       +1 -0      httpd-test/perl-framework/Apache-Test/lib/Apache/TestCommon.pm
  
  Index: TestCommon.pm
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestCommon.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestCommon.pm	11 Dec 2001 05:11:40 -0000	1.2
  +++ TestCommon.pm	2 Apr 2002 04:08:33 -0000	1.3
  @@ -8,6 +8,7 @@
   use Apache::Test;
   use Apache::TestRequest;
   use Apache::TestUtil;
  +use Apache::TestCommonPost ();
   
   #this module contains common tests that are called from different .t files
   
  
  
  
  1.1                  httpd-test/perl-framework/Apache-Test/lib/Apache/TestCommonPost.pm
  
  Index: TestCommonPost.pm
  ===================================================================
  package Apache::TestCommonPost;
  
  use strict;
  use warnings FATAL => 'all';
  
  use constant POST_HUGE => $ENV{APACHE_TEST_POST_HUGE} || 0;
  
  use Apache::TestRequest ();
  use Apache::TestUtil qw(t_cmp t_debug);
  use Apache::Test qw(sok);
  
  BEGIN {
      my $use_inline = 0;
  
      eval {
          #if Inline.pm and libcurl are available
          #we can make this test about 3x faster,
          #after the inlined code is compiled that is.
          require Inline;
          Inline->import(C => 'DATA', LIBS => ['-lcurl'],
                         #CLEAN_AFTER_BUILD => 0,
                         PREFIX => 'aptest_post_');
          *request_init = \&curl_init;
          *request_do   = \&curl_do;
          $use_inline = 1;
      } if POST_HUGE;
  
      if (POST_HUGE) {
          if ($@) {
              t_debug "tests will run faster with Inline and curl installed";
              print $@;
          }
          else {
              t_debug "using Inline and curl client";
          }
      }
  
      unless ($use_inline) {
          t_debug "using LWP client";
          #fallback to lwp
          *request_init = \&lwp_init;
          *request_do   = \&lwp_do;
      }
  }
  
  sub lwp_init {
      use vars qw($UA $Location);
      $UA = Apache::TestRequest::user_agent(reset => 1);
      $Location = shift;
  }
  
  sub lwp_do {
      my $length = shift;
      my $remain = $length;
  
      use constant BUF_SIZE => 8192;
  
      my $content = sub {
          my $bytes = $remain < BUF_SIZE ? $remain : BUF_SIZE;
          my $buf = 'a' x $bytes;
          $remain -= $bytes;
          $buf;
      };
  
      my $request = HTTP::Request->new(POST => $Location);
      $request->header('Content-length' => $length);
      $request->content($content);
  
      my $response = $UA->request($request);
  
      Apache::TestRequest::lwp_trace($response);
  
      return $response->content;
  }
  
  my @run_post_test_small_sizes =
    #1k..9k, 10k..50k, 100k
    (1..9, 10..50, 100);
  
  my @run_post_test_sizes = @run_post_test_small_sizes;
  
  if (POST_HUGE) {
      push @run_post_test_sizes,
        #300k, 500k, 2Mb, 4Mb, 6Mb, 10Mb
        300, 500, 2000, 4000, 6000, 10_000;
  }
  
  sub Apache::TestCommon::run_post_test_sizes { @run_post_test_sizes }
  
  sub Apache::TestCommon::run_post_test {
      my $module = shift;
      my $sizes = shift || \@run_post_test_sizes;
  
      my $location = Apache::TestRequest::resolve_url("/$module");
  
      request_init($location);
  
      for my $size (@$sizes) {
          sok {
              my $length = ($size * 1024);
  
              my $str = request_do($length);
              chomp $str;
  
              t_cmp($length, $str, "length posted");
          };
      }
  }
  
  1;
  __DATA__
  
  __C__
  
  #include <curl/curl.h>
  #include <curl/easy.h>
  
  static CURL *curl = NULL;
  static SV *response = Nullsv;
  static long total = 0;
  
  static size_t my_curl_read(char *buffer, size_t size,
                             size_t nitems, void *data)
  {
      size_t bytes = nitems < total ? nitems : total;
      memset(buffer, 'a', bytes);
      total -= bytes;
      return bytes;
  }
  
  static size_t my_curl_write(char *buffer, size_t size,
                              size_t nitems, void *data)
  {
      sv_catpvn(response, buffer, nitems);
      return nitems;
  }
  
  void aptest_post_curl_init(char *url)
  {
      char *proto = "HTTP/1.1"; /* curl default */
      curl = curl_easy_init();
      curl_easy_setopt(curl, CURLOPT_MUTE, 1);
      curl_easy_setopt(curl, CURLOPT_URL, url);
      curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
      curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
      curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_curl_read);
      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_curl_write);
      if (!getenv("APACHE_TEST_HTTP11")) {
          curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
          proto = "HTTP/1.0";
      }
      fprintf(stdout, "#CURL using protocol %s\n", proto);
      fflush(stdout);
      response = newSV(0);
  }
  
  SV *aptest_post_curl_do(long len)
  {
      sv_setpv(response, "");
      total = len;
      curl_easy_setopt(curl, CURLOPT_INFILESIZE, len);
      curl_easy_perform(curl);
      return SvREFCNT_inc(response);
  }
  
  void aptest_post_END(void)
  {
      if (response) {
          SvREFCNT_dec(response);
      }
      if (curl) {
          curl_easy_cleanup(curl);
      }
  }
  
  
  
  1.2       +8 -140    httpd-test/perl-framework/t/http11/post.t
  
  Index: post.t
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/t/http11/post.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- post.t	19 Jan 2002 04:23:38 -0000	1.1
  +++ post.t	2 Apr 2002 04:08:33 -0000	1.2
  @@ -1,149 +1,17 @@
   use strict;
   use warnings FATAL => 'all';
   
  -use constant POST_HUGE => $ENV{APACHE_TEST_POST_HUGE} || 0;
  -
  -use vars '$client_module';
  -
  -BEGIN {
  -    eval {
  -        #if Inline.pm and libcurl are available
  -        #we can make this test about 3x faster,
  -        #after the inlined code is compiled that is.
  -        require Inline;
  -        Inline->import(C => 'DATA', LIBS => ['-lcurl'],
  -                       #CLEAN_AFTER_BUILD => 0,
  -                       PREFIX => 'http11_post_');
  -        *request_init = \&curl_init;
  -        *request_do   = \&curl_do;
  -        $client_module = 'Inline';
  -    } if POST_HUGE;
  -
  -    unless ($client_module) {
  -        #fallback to lwp
  -        *request_init = \&lwp_init;
  -        *request_do   = \&lwp_do;
  -        $client_module = 'LWP';
  -    }
  -}
  -
   use Apache::Test;
  -use Apache::TestRequest;
  -use Apache::TestUtil;
  -
  -#test some sizes too large for mod_echo_post
  -#and keep the connection alive for kicks
  -
  -#1k..9k, 10k..50k, 100k, 300k, 500k, 2Mb
  -my @sizes = (1..9, 10..50, 100, 300, 500, 2000);
  -
  -#these are too slow to be on by default
  -#4Mb, 6Mb, 10Mb, 50Mb, 100Mb
  -my @huge_sizes = (4000, 6000, 10_000, 50_000, 100_000);
  -
  -push @sizes, @huge_sizes if POST_HUGE;
  -
  -plan tests => scalar @sizes, [qw(eat_post), $client_module];
  -
  -my $location = Apache::TestRequest::resolve_url("/eat_post");
  -
  -request_init($location);
  -
  -for my $size (@sizes) {
  -    sok {
  -        my $length = ($size * 1024);
  -
  -        my $str = request_do($length);
  -        chomp $str;
  -
  -        t_cmp($length, $str, "length posted");
  -    };
  -}
  -
  -sub lwp_init {
  -    use vars '$UA';
  -    $UA = Apache::TestRequest::user_agent(keep_alive => 1);
  -}
  -
  -sub lwp_do {
  -    my $length = shift;
  -    my $remain = $length;
  -
  -    use constant BUF_SIZE => 8192;
  -
  -    my $content = sub {
  -        my $bytes = $remain < BUF_SIZE ? $remain : BUF_SIZE;
  -        my $buf = 'a' x $bytes;
  -        $remain -= $bytes;
  -        $buf;
  -    };
  -
  -    my $request = HTTP::Request->new(POST => $location);
  -    $request->header('Content-length' => $length);
  -    $request->content($content);
  -
  -    my $response = $UA->request($request);
  -
  -    #t_debug $request->headers_as_string;
  -    #t_debug $response->headers_as_string;
  -
  -    return $response->content;
  -}
  -
  -__DATA__
  -
  -__C__
  -
  -#include <curl/curl.h>
  -#include <curl/easy.h>
  -
  -static CURL *curl = NULL;
  -static SV *response = Nullsv;
  -static long total = 0;
  +use Apache::TestCommon ();
   
  -static size_t my_curl_read(char *buffer, size_t size,
  -                           size_t nitems, void *data)
  -{
  -    size_t bytes = nitems < total ? nitems : total;
  -    memset(buffer, 'a', bytes);
  -    total -= bytes;
  -    return bytes;
  -}
  +local $ENV{APACHE_TEST_HTTP11} = 1;
   
  -static size_t my_curl_write(char *buffer, size_t size,
  -                            size_t nitems, void *data)
  -{
  -    sv_catpvn(response, buffer, nitems);
  -    return nitems;
  -}
  +#same as t/apache/post but turn on HTTP/1.1
  +Apache::TestRequest::user_agent(keep_alive => 1);
   
  -void http11_post_curl_init(char *url)
  -{
  -    curl = curl_easy_init();
  -    curl_easy_setopt(curl, CURLOPT_MUTE, 1);
  -    curl_easy_setopt(curl, CURLOPT_URL, url);
  -    curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
  -    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  -    curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_curl_read);
  -    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_curl_write);
  -    response = newSV(0);
  -}
  +my $module = 'eat_post';
  +my $num = Apache::TestCommon::run_post_test_sizes();
   
  -SV *http11_post_curl_do(long len)
  -{
  -    sv_setpv(response, "");
  -    total = len;
  -    curl_easy_setopt(curl, CURLOPT_INFILESIZE, len);
  -    curl_easy_perform(curl);
  -    return SvREFCNT_inc(response);
  -}
  +plan tests => $num, [$module];
   
  -void http11_post_END(void)
  -{
  -    if (response) {
  -        SvREFCNT_dec(response);
  -    }
  -    if (curl) {
  -        curl_easy_cleanup(curl);
  -    }
  -}
  +Apache::TestCommon::run_post_test($module);
  
  
  

Mime
View raw message