Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reduce the time for another test from ~9sec to ~3.5sec.

  • Loading branch information...
commit a99ffee13fa9a7d149479f89b20855ec4f299e9d 1 parent 49b986f
Rocco Caputo authored
Showing with 32 additions and 10 deletions.
  1. +32 −10 lib/POE/Test/Loops/z_rt54319_bazerka_followtail.pm
42 lib/POE/Test/Loops/z_rt54319_bazerka_followtail.pm
View
@@ -1,17 +1,22 @@
#! /usr/bin/env perl
# vim: ts=2 sw=2 expandtab
-# Verify that POE::Wheel::FollowTail does indeed follow a file's tail.
-
use strict;
use warnings;
+sub POE::Kernel::CATCH_EXCEPTIONS () { 0 }
+sub POE::Kernel::ASSERT_DEFAULT () { 1 }
+
+use Time::HiRes qw(time);
use IO::Handle;
use POE qw(Wheel::FollowTail);
-use constant TESTS => 10;
-use Test::More;
+use constant {
+ TESTS => 6,
+ TIME_BETWEEN_WRITES => 0.5,
+};
+use Test::More;
use File::Temp;
# Sanely generate the tempfile
@@ -22,7 +27,10 @@ plan skip_all => "Unable to create tempfile for testing" if $@;
$write_fh->autoflush(1);
my $write_count = 0;
-plan tests => 10;
+plan tests => TESTS;
+
+# Write to the log 2x as fast as it's polled.
+# Make sure none of the lines is delayed overly long.
POE::Session->create(
inline_states => {
@@ -31,32 +39,46 @@ POE::Session->create(
},
on_tick => sub {
print $write_fh ++$write_count, " ", time(), "\n";
- $_[KERNEL]->delay("on_tick" => 1) if $write_count < TESTS;
+ $_[KERNEL]->delay("on_tick" => TIME_BETWEEN_WRITES) if $write_count < TESTS;
},
+ _stop => sub { undef },
}
);
+# Read from the log at one check every 3 seconds.
+
+my $poll_interval = TIME_BETWEEN_WRITES * 2;
+my $per_test_timeout = TIME_BETWEEN_WRITES * 3;
+
POE::Session->create(
inline_states => {
_start => sub {
$_[HEAP]{tailor} = POE::Wheel::FollowTail->new(
Filename => $write_fh->filename,
InputEvent => "got_log_line",
- PollInterval => 3,
+ PollInterval => $poll_interval,
);
- $_[KERNEL]->delay(timeout => 20);
+
+ # A long timeout to begin with.
+ $_[KERNEL]->delay(timeout => $poll_interval * TESTS);
},
got_log_line => sub {
my ($write, $time) = split /\s+/, $_[ARG0];
- my $elapsed = time() - $time;
- ok($elapsed <= 6, "response time <=6 seconds ($elapsed)");
+ my $elapsed = sprintf("%.2f", time() - $time);
+ ok(
+ $elapsed <= $per_test_timeout,
+ "response time <= $per_test_timeout sec ($elapsed)"
+ );
return if $write < TESTS;
+
+ # Stop the timeout when we're done.
$_[KERNEL]->delay(timeout => undef);
delete $_[HEAP]{tailor};
},
timeout => sub {
delete $_[HEAP]{tailor};
},
+ _stop => sub { undef },
}
);
Please sign in to comment.
Something went wrong with that request. Please try again.