summaryrefslogtreecommitdiffstats
path: root/debian/perl-framework/Apache-Test/t/log_watch_for_broken_lines.t
blob: 108e10ca5b7614bcae433fba60fa7e2a4afbdb5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!perl

use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil qw/t_start_file_watch t_file_watch_for
			t_cmp t_catfile t_append_file/;

plan tests => 5, need_fork;

my $fn=t_catfile(Apache::Test::vars->{t_logs}, 'watch');
unlink $fn;

t_start_file_watch 'watch';

my $pid;
select undef, undef, undef, 0.1 until defined($pid=fork);
unless ($pid) {			# child
    t_append_file $fn, "\nhuhu\n4 5 6 \nblabla\n";
    for(1..3) {
	select undef, undef, undef, 0.3;
	t_append_file $fn, "$_ ";
    }
    t_append_file $fn, "\nhuhu\n4 5 6 \nblabla";
    exit 0;
}

ok t_cmp t_file_watch_for('watch', qr/^1 2 3 $/, 2),
    "1 2 3 \n", 'incomplete line';

my @lines=t_file_watch_for('watch', qr/^\d \d \d $/, 2);
ok t_cmp @lines, 2, '2 lines';
ok t_cmp $lines[0], "huhu\n", '1st line';
ok t_cmp $lines[1], "4 5 6 \n", 'found it';

ok t_cmp t_file_watch_for('watch', qr/^\d \d \d $/, 0.3),
    undef, 'timeout';

waitpid $pid, 0;