Skip to content

Commit 1182968

Browse files
committed
Add support for timing out the bots
1 parent e17c571 commit 1182968

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Perl6IRCBotable.pm

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use Cwd qw(cwd abs_path);
2828
use Encode qw(encode_utf8 decode_utf8);
2929
use File::Temp qw(tempfile tempdir);
3030
use HTTP::Tiny;
31-
use IO::Handle;
31+
#use IO::Handle;
3232
use IPC::Open3;
3333
use JSON::XS;
3434
use Net::GitHub;
@@ -41,17 +41,28 @@ use constant SOURCE => 'https://github.com/perl6/bisectbot';
4141

4242
$ENV{'RAKUDO_ERROR_COLOR'} = 0;
4343

44+
sub timeout {
45+
return 10;
46+
}
47+
4448
sub get_output {
4549
my $self = shift;
4650

51+
my $out = undef;
52+
my $wait = $self->timeout();
4753
my $s_start = time();
4854
my $pid = open3(undef, \*RESULT, \*RESULT, @_);
49-
waitpid($pid, 0);
55+
{
56+
local $SIG{ALRM} = sub { kill 9, $pid; $out = "timed out after $wait seconds"; };
57+
alarm $wait;
58+
waitpid($pid, 0);
59+
alarm 0;
60+
}
5061
my $s_end = time();
5162

5263
my $exit_status = $? >> 8;
5364

54-
my $out = do { local $/; <RESULT> };
65+
$out = do { local $/; <RESULT> } unless defined $out;
5566
chomp $out if defined $out;
5667

5768
return ($out, $exit_status, $s_end - $s_start)

benchable.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ package Benchable;
3636

3737
my $name = 'benchable';
3838

39+
sub timeout {
40+
return 200;
41+
}
42+
3943
sub process_message {
4044
my ($self, $message, $body) = @_;
4145

bisectable.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ package Bisectable;
3434
my $commit_tester = abs_path('./test-commit');
3535
my $build_lock = abs_path('./lock');
3636

37+
sub timeout {
38+
return 200;
39+
}
40+
3741
sub process_message {
3842
my ($self, $message, $body) = @_;
3943

committable.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ package Committable;
3131

3232
my $name = 'committable';
3333

34+
sub timeout {
35+
return 50;
36+
}
37+
3438
sub process_message {
3539
my ($self, $message, $body) = @_;
3640

0 commit comments

Comments
 (0)