File: 100_account_for_signal.t

package info (click to toggle)
libyahc-perl 0.035-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 440 kB
  • sloc: perl: 3,661; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 856 bytes parent folder | download | duplicates (2)
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
41
#!/usr/bin/env perl

use strict;
use warnings;

use YAHC;
use Test::More;
use Time::HiRes qw/time/;

my ($yahc, $yahc_storage) = YAHC->new({
    account_for_signals => 1
});

my $alrm = 2;
my $timeout = 3;

my $timer_called = 0;
$yahc->loop->now_update();
my $w = $yahc->loop->timer($timeout, 0, sub {
    $timer_called = 1;
    $yahc->break('break because of timeout');
});

my $sigalrm_called = 0;
$SIG{ALRM} = sub {
    $sigalrm_called = 1;
    $yahc->break('break becuase of SIGALRM');
};

alarm($alrm);

my $start = time;
$yahc->run;
my $elapsed = time - $start;

ok($sigalrm_called == 1, 'SIGALRM handler has been called');
ok($timer_called == 0, 'timer handler has not been called');
cmp_ok($elapsed, '>=', $alrm, "SIGALRM was called at >= $alrm seconds");
cmp_ok($elapsed, '<', $timeout, "SIGALRM was called at < $timeout seconds");

done_testing;