File: 53-signal.t

package info (click to toggle)
libredis-fast-perl 0.22%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 488 kB
  • sloc: perl: 2,539; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 1,094 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
42
43
44
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Redis::Fast;
use lib 't/tlib';
use Test::SpawnRedisServer;
use Time::HiRes qw();

my ($c, $srv) = redis();
END { $c->() if $c }


my $redis;
is(
  exception { $redis = Redis::Fast->new(server => $srv, name => 'my_name_is_glorious') },
  undef, 'connected to our test redis-server',
);
ok($redis->ping, 'ping');

$redis->select(2);

subtest 'signal' => sub {
    my $start = Time::HiRes::time;
    my $sig;
    local $SIG{ALRM} = sub { $sig = Time::HiRes::time };
    alarm 1;
    $redis->blpop('abc', 5);
    my $end = Time::HiRes::time;
    cmp_ok $sig - $start, '<=', 2, 'the signal handler is executed as soon as possible';
    cmp_ok $end - $start, '>=', 4, 'the signal does not unblock the Redis command';
};

subtest 'die in signal' => sub {
    my $start = Time::HiRes::time;
    local $SIG{ALRM} = sub { die "ALARM\n"; };
    alarm 1;
    is exception {  $redis->blpop('abc', 20); }, "ALARM\n";
    my $end = Time::HiRes::time;
    cmp_ok $end - $start, '<=', 2, 'the signal unblocks the Redis command';
};

done_testing;