Skip to content

Commit

Permalink
Fix more race conditions and minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
exodist committed Apr 10, 2024
1 parent 2c8e656 commit f46ca94
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
14 changes: 7 additions & 7 deletions lib/App/Yath/Options/Resource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ option_group {group => 'resource', category => "Resource Options"} => sub {
clear_env_vars => [qw/YATH_JOB_COUNT T2_HARNESS_JOB_COUNT HARNESS_JOB_COUNT/],

default => sub {
if (eval { require System::Info; System::Info->can('ncore') ? 1 : 0 }) {
my $count = System::Info->new->ncore;
if ($count > 2) {
$count /= 2;
print "System::Info is installed, setting job count to $count (Half the cores on this system)\n";
return $count;
my $ncore = eval { require System::Info; System::Info->new->ncore } || 0;
if ($ncore) {
if ($ncore > 2) {
$ncore /= 2;
print "System::Info is installed, setting job count to $ncore (Half the cores on this system)\n";
return $ncore;
}
else {
print "System::Info is installed, setting job count to 2 (Because we have less than 3 cores)\n";
return 2;
}
}

print "System::Info is not installed, setting job count to 2.\n";
print "Setting job count to 2. Install a sufficient version of System::Info to have this default to half the total number of cores.\n";
return 2;
},

Expand Down
6 changes: 4 additions & 2 deletions lib/App/Yath/Renderer/Logger.pm
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ sub start {
print "Opened log file: $file\n";

my $link = normalize_log_file(lastlog => $self->settings);
symlink($file => $link) or die "Could not create symlink $file -> $link: $!";
unless ($file eq $link) {
symlink($file => $link) or die "Could not create symlink $file -> $link: $!";
print "Linked log file: $link\n";
}

print "Linked log file: $link\n";
}

sub render_event {
Expand Down
15 changes: 15 additions & 0 deletions lib/App/Yath/Tester.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ sub yath {
my $enc = delete $params{encoding};
my $prefix = delete $params{prefix};

my $timeout = delete $params{timeout};
my $timeout_cb = delete $params{timeout_cb};

my $subtest = delete $params{test} // delete $params{tests} // delete $params{subtest};
my $exittest = delete $params{exit};

Expand Down Expand Up @@ -114,6 +117,16 @@ sub yath {
swap_io(\*STDERR, $wh);
};

local $SIG{ALRM};
if ($timeout) {
$SIG{ALRM} = sub {
$timeout_cb->($pid) if $timeout_cb;
kill('TERM', $pid);
};

alarm($timeout);
}

my $our_pid = $$;
eval "END{ kill('TERM', \$pid) if \$pid && \$\$ == $our_pid }; 1" or die $@;

Expand Down Expand Up @@ -146,6 +159,8 @@ sub yath {
$exit = $?;
}

alarm(0) if $timeout;

$pid = undef;

print "DEBUG: Exit: $exit\n" if $debug;
Expand Down
4 changes: 4 additions & 0 deletions lib/Test2/Harness/Collector.pm
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,10 @@ sub _process {
}

if (defined $exited) {
for my $h (@$handles) {
my ($x, $y, %params) = @$h;
return 0 unless $params{eof}->();
}
return 1 if !$auditor;
return 1 if $auditor->has_plan;
return 1 if $exit; # If the exit value is not true we do not wait for post-exit timeout
Expand Down
2 changes: 1 addition & 1 deletion lib/Test2/Harness/Reloader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ sub find_files_to_watch {
%watches = %{$stage->watches};
}

for my $file (map { clean_path($_) } values %INC) {
for my $file (map { $_ ? clean_path($_) : () } values %INC) {
next if ref $file;
next unless -e $file;
next unless $self->should_watch($file);
Expand Down
2 changes: 2 additions & 0 deletions lib/Test2/Harness/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ our @EXPORT_OK = (
sub clean_path {
my ( $path, $absolute ) = @_;

confess "No path was provided to clean_path()" unless $path;

$absolute //= 1;
$path = realpath($path) // $path if $absolute;

Expand Down

0 comments on commit f46ca94

Please sign in to comment.