blib/lib/POE/Test/Loops/z_rt54319_bazerka_followtail.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 68 CC 1 SCAR 6.9
CC
1
Cov
0%
POE::Kernel::CATCH_EXCEPTIONS
2.0
POE::Kernel::ASSERT_DEFAULT
2.0
BEGIN
2.0
CRAP 2.0
1 #! /usr/bin/env perl
2 # vim: ts=2 sw=2 expandtab
3  
4 use strict;
5 use warnings;
6  
7 sub POE::Kernel::CATCH_EXCEPTIONS () { 0 }
8 sub POE::Kernel::ASSERT_DEFAULT () { 1 }
9  
10 use Time::HiRes qw(time);
11 use IO::Handle;
12 use POE qw(Wheel::FollowTail);
13  
14 use constant {
15 TESTS => 6,
16 TIME_BETWEEN_WRITES => 0.5,
17 };
18  
19 use Test::More;
20 use File::Temp;
21  
22 # Sanely generate the tempfile
23 my $write_fh;
24 eval { $write_fh = File::Temp->new( UNLINK => 1 ) };
25 plan skip_all => "Unable to create tempfile for testing" if $@;
26  
27 $write_fh->autoflush(1);
28 my $write_count = 0;
29  
30 plan tests => TESTS;
31  
32 # Write to the log 2x as fast as it's polled.
33 # Make sure none of the lines is delayed overly long.
34  
35 POE::Session->create(
36 inline_states => {
37 _start => sub {
38 $_[KERNEL]->yield("on_tick");
39 },
40 on_tick => sub {
41 print $write_fh ++$write_count, " ", time(), "\n";
42 $_[KERNEL]->delay("on_tick" => TIME_BETWEEN_WRITES) if $write_count < TESTS;
43 },
44 _stop => sub { undef },
45 }
46 );
47  
48 # Read from the log at one check every 3 seconds.
49  
50 my $poll_interval = TIME_BETWEEN_WRITES * 2;
51 my $per_test_timeout = TIME_BETWEEN_WRITES * 3;
52  
53 POE::Session->create(
54 inline_states => {
55 _start => sub {
56 $_[HEAP]{tailor} = POE::Wheel::FollowTail->new(
57 Filename => $write_fh->filename,
58 InputEvent => "got_log_line",
59 PollInterval => $poll_interval,
60 );
61  
62 # A long timeout to begin with.
63 $_[KERNEL]->delay(timeout => $poll_interval * TESTS);
64 },
65 got_log_line => sub {
66 my ($write, $time) = split /\s+/, $_[ARG0];
67 my $elapsed = sprintf("%.2f", time() - $time);
68 ok(
69 $elapsed <= $per_test_timeout,
70 "response time <= $per_test_timeout sec ($elapsed)"
71 );
72 return if $write < TESTS;
73  
74 # Stop the timeout when we're done.
75 $_[KERNEL]->delay(timeout => undef);
76 delete $_[HEAP]{tailor};
77 },
78 timeout => sub {
79 delete $_[HEAP]{tailor};
80 },
81 _stop => sub { undef },
82 }
83 );
84  
85 POE::Kernel->run();
86  
87 1;