File: select-timeout.t

package info (click to toggle)
libhijk-perl 0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 332 kB
  • ctags: 198
  • sloc: perl: 3,070; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download
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
42
43
44
45
46
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Exception;

use Hijk;
use Time::HiRes;

my $parent_pid = $$;
pipe(my $rh, my $wh) or die "Failed to create pipe: $!";

my $pid = fork;
die "Fail to fork then start a plack server" unless defined $pid;

if ($pid == 0) {
    Time::HiRes::sleep(0.5);
    for (1..10) {
        kill('HUP', $parent_pid);
        Time::HiRes::sleep(0.1);
    }
    exit;
}

$SIG{HUP} = sub { warn "SIGHUP received\n" };

my $timeout = 2;
vec(my $rin = '', fileno($rh), 2) = 1;

my $start = Time::HiRes::time;
Hijk::_select($rin, undef, undef, $timeout);
my $elapsed = Time::HiRes::time - $start;

{
    my $msg = sprintf("handle signal during select, took=%.2fs, expected at least=%.2fs", $elapsed, $timeout);
    if ($elapsed >= $timeout) {
        pass($msg);
    } else {
        TODO: {
            local $TODO = "We don't know why, but this fails on various BSDs etc. It is known, and probably some general OS issue. Don't clutter CPANtesters with it";
            fail($msg);
        }
    }
}

done_testing;