File: 50-fork_safe.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 (32 lines) | stat: -rw-r--r-- 751 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More;
use Redis::Fast;
use lib 't/tlib';
use Test::SpawnRedisServer;
use Test::SharedFork;
use Socket;

my ($c, $srv) = redis();
END { $c->() if $c }
my $o = Redis::Fast->new(server => $srv, name => 'my_name_is_glorious');
is $o->info->{connected_clients}, 1;
my $localport = $o->__get_port;

note "fork safe"; {
    if (my $pid = fork) {
        $o->incr("test-fork");
        is $o->__get_port, $localport, "same port on parent";
        waitpid($pid, 0);
    }
    else {
        $o->incr("test-fork");
        isnt $o->__get_port, $localport, "different port on child";
        is $o->info->{connected_clients}, 2, "2 clients connected";
        exit 0;
    }

    is $o->get('test-fork'), 2;
};

done_testing;