package TaskForest::Test; use strict; use warnings; BEGIN { use vars qw($VERSION); $VERSION = '1.30'; } use Test::More; sub checkStatusText { my ($content, $expected_lines) = @_; my @received_lines = split(/[\r?\n]/, $content); my @status = (); my ($regex, $line); while ( defined ($line = shift(@received_lines))) { last if $line eq ""; } while (@received_lines) { my $expected_line = shift(@$expected_lines); my ($family, $job, $status, $rc, $tz, $start, $astart, $stop) = @$expected_line; my ($jb) = $job =~ /([^\-]+)/; $line = shift(@received_lines); $regex = "${family}::$job +$status +$rc +$tz +$start +$astart +$stop"; like($line, qr/$regex/, "Got Line $line"); } if (@$expected_lines) { diag("ERROR: expected a few more lines than we got"); die; } } sub checkStatus { my ($content, $expected_lines) = @_; my @received_lines = split(/[\r?\n]/, $content); my @status = (); my $html; while ( defined ($html = shift(@received_lines))) { last if $html eq "
"; } while ($received_lines[0] ne "
") { my $expected_line = shift(@$expected_lines); my ($family, $job, $status, $rc, $tz, $start, $astart, $stop) = @$expected_line; my ($jb) = $job =~ /([^\-]+)/; $html = shift(@received_lines); is($html, qq[
], "Got '
', "); $html = shift(@received_lines); is($html, qq[
Family Name
], "Got '
Family Name
', "); $html = shift(@received_lines); is($html, qq[
$family
],"Got '
$family
'"); $html = shift(@received_lines); is($html, qq[
Job Name
], "Got '
Job Name
', "); $html = shift(@received_lines); is($html, qq[
$job
], "Got '
$job
', "); $html = shift(@received_lines); is($html, qq[
Status
], "Got '
Status
', "); $html = shift(@received_lines); is($html, qq[
$status
], "Got '
$status
', "); $html = shift(@received_lines); is($html, qq[
Return Code
], "Got '
Return Code
', "); $html = shift(@received_lines); is($html, qq[
$rc
], "Got '
$rc
', "); $html = shift(@received_lines); is($html, qq[
Time Zone
], "Got '
Time Zone
', "); $html = shift(@received_lines); is($html, qq[
$tz
], "Got '
$tz
', "); $html = shift(@received_lines); is($html, qq[
Scheduled Start Time
], "Got '
Scheduled Start Time
', "); $html = shift(@received_lines); is($html, qq[
$start
], "Got '
$start
', "); $html = shift(@received_lines); is($html, qq[
Actual Start Time
], "Got '
Actual Start Time
', "); $html = shift(@received_lines); is($html, qq[
$astart
], "Got '
$astart
', "); $html = shift(@received_lines); is($html, qq[
Stop Time
], "Got '
Stop Time
', "); $html = shift(@received_lines); is($html, qq[
$stop
], "Got '
$stop
', "); $html = shift(@received_lines); is($html, qq[
], "Got '
', "); } } sub cleanup_files { my $dir = shift; local *DIR; opendir DIR, $dir or die "opendir $dir: $!"; my $found = 0; while ($_ = readdir DIR) { next if /^\.{1,2}$/; my $path = "$dir/$_"; unlink $path if -f $path; } closedir DIR; } sub fakeRun { my ($log_dir, $family, $job, $status) = @_; open (OUT, ">$log_dir/$family.$job.pid") || die "Couldn't open pid file\n"; print OUT "pid: 111\nactual_start: 1209270000\nstop: 1209270001\nrc: $status\n"; close OUT; open (OUT, ">$log_dir/$family.$job.started") || die "Couldn't open started file\n"; print OUT "00:00\n"; close OUT; open (OUT, ">$log_dir/$family.$job.$status") || die "Couldn't open pid file\n"; print OUT "$status\n"; close OUT; } sub waitForFiles { my %args = @_; my $sleep_time = $args{sleep_time} || 3; my $num_tries = $args{num_tries} || 10; my $file_list = $args{file_list}; next unless @$file_list; my $num_files = scalar(@$file_list); for (my $n = 1; $n <= $num_tries; $n++) { sleep $sleep_time; my $found = 1; my @missing = (); foreach my $file (@$file_list) { if (! -e $file) { $found = 0; push (@missing, $file); } } return 1 if $found; diag("Loop # $n: missing the following files:\n ", join("\n ", @missing), "\n") unless $n %5; } return 0; } 1;