Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reduce the time for another FollowTail test from ~5sec to ~0.2sec.

  • Loading branch information...
commit ec6842f343367e2b49c5d21ae93df4fab99dd91e 1 parent 9e042d0
@rcaputo authored
Showing with 25 additions and 3 deletions.
  1. +25 −3 t/90_regression/bingos-followtail.t
View
28 t/90_regression/bingos-followtail.t
@@ -1,6 +1,10 @@
#!/usr/bin/perl -w
# vim: ts=2 sw=2 filetype=perl expandtab
+# Make sure that the default behavior for POE::Wheel::FollowTail is to
+# skip to the end of the file when it first starts.
+
+use warnings;
use strict;
sub POE::Kernel::ASSERT_DEFAULT () { 1 }
@@ -12,13 +16,14 @@ use Test::More tests => 2;
my $filename = 'bingos-followtail';
# Using "!" as a newline to avoid differences in opinion about "\n".
+
open FH, ">$filename" or die "$!\n";
FH->autoflush(1);
print FH "moocow - this line should be skipped!";
POE::Session->create(
package_states => [
- 'main' => [qw(_start _input _error _shutdown)],
+ 'main' => [qw(_start _input _error _shutdown _file_is_idle)],
],
inline_states => {
_stop => sub { undef },
@@ -36,8 +41,12 @@ sub _start {
Filename => $heap->{filename},
InputEvent => '_input',
ErrorEvent => '_error',
+ IdleEvent => '_file_is_idle',
);
+
+ $heap->{running} = 1;
$heap->{counter} = 0;
+
print FH "Cows go moo, yes they do!";
close FH;
return;
@@ -54,14 +63,27 @@ sub _input {
# Make sure we got the right line.
is($input, 'Cows go moo, yes they do', 'Got the right line');
ok( ++$heap->{counter} == 1, 'Cows went moo' );
- $kernel->delay( '_shutdown', 5 ); # Wait five seconds.
+ POE::Kernel->delay( _shutdown => 5 );
return;
}
sub _error {
my ($heap,$operation, $errnum, $errstr, $wheel_id) = @_[HEAP,ARG0..ARG3];
diag("Wheel $wheel_id generated $operation error $errnum: $errstr\n");
- delete $heap->{wheel};
+ POE::Kernel->delay( _shutdown => 0.01 );
return;
}
+sub _file_is_idle {
+ return unless $_[HEAP]{counter};
+
+ # At first I thought just a delay( _shutdown => 1 ) would be nice
+ # here, but there's a slight chance that the POE::Wheel::FollowTail
+ # polling interval could refresh this indefinitely.
+ #
+ # So I took the slightly more awkward course of turning off the
+ # shutdown timer and triggering shutdown immediately.
+
+ POE::Kernel->delay(_shutdown => undef);
+ POE::Kernel->yield("_shutdown");
+}
Please sign in to comment.
Something went wrong with that request. Please try again.