perl-modperl-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject cvs commit: modperl-2.0/t/filter/TestFilter
Date Mon, 03 Mar 2003 03:42:06 GMT
stas        2003/03/02 19:42:06

  Added:       t/filter out_str_declined.t
  add a test testing how the declined is handled in the output filters,
  plus it also verifies that rflush and unbuffered print are handled
  correctly (by counting the number of resulting filter invocations, which
  happens for each bb sent)
  Revision  Changes    Path
  1.1                  modperl-2.0/t/filter/out_str_declined.t
  Index: out_str_declined.t
  use strict;
  use warnings FATAL => 'all';
  use Apache::Test;
  use Apache::TestRequest;
  use Apache::TestUtil;
  plan tests => 1;
  my $expected = 11; # 10 flushes and 1 EOS bb
  my $location = '/TestFilter::out_str_declined';
  my $response = GET_BODY $location;
  ok t_cmp($expected, $response, "an output filter handler returning DECLINED");
  1.1                  modperl-2.0/t/filter/TestFilter/
  package TestFilter::out_str_declined;
  use strict;
  use warnings FATAL => 'all';
  use Apache::Test;
  use Apache::TestUtil;
  use Apache::RequestRec ();
  use Apache::RequestIO ();
  use Apache::Filter ();
  use Apache::Const -compile => qw(OK DECLINED);
  use constant READ_SIZE  => 1024;
  # make sure that if the input filter returns DECLINED without
  # reading/printing data the data flow is not broken
  sub decline {
        my $filter = shift;
        my $ctx = $filter->ctx;
        # can't use $f->seen_eos, since we don't read the data, so
        # we have to set the note on each invocation
        $filter->r->notes->set(invoked => $ctx->{invoked});
        #warn "decline    filter was invoked $ctx->{invoked} times\n";
        return Apache::DECLINED;
  # this filter ignores all the data that comes through, though on the
  # last invocation it prints how many times the filter 'decline' was called
  # which it could count by itself, but we want to test that 
  # 'return Apache::DECLINED' works properly in output filters
  sub black_hole {
      my $filter = shift;
      my $ctx = $filter->ctx;
      #warn "black_hole filter was invoked $ctx->{invoked} times\n";
      while ($filter->read(my $data, READ_SIZE)) {
          #warn "black_hole data: $data\n";
          # let the data fall between the chairs
      if ($filter->seen_eos) {
          my $invoked = $filter->r->notes->get('invoked') || 0;
      return Apache::OK;
  sub response {
      my $r = shift;
      # just to make sure that print() won't flush, or we would get the
      # count wrong
      local $| = 0;
      for (1..10) {
          $r->print("a"); # this buffers the data
          $r->rflush;     # this sends the data in the buffer + flush bucket
  SetHandler modperl
  PerlResponseHandler     TestFilter::out_str_declined::response
  PerlOutputFilterHandler TestFilter::out_str_declined::decline
  PerlOutputFilterHandler TestFilter::out_str_declined::black_hole

View raw message