File: 50-fork_safe.t

package info (click to toggle)
libredis-perl 2%3A2.000-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 416 kB
  • sloc: perl: 2,695; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 974 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
use strict;
use warnings;
use Test::More;
use Redis;
use lib 't/tlib';
use Test::SpawnRedisServer;
use Test::SharedFork;

use constant SSL_AVAILABLE => eval { require IO::Socket::SSL } || 0;

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

my $use_ssl = $t ? SSL_AVAILABLE : 0;

my $o = Redis->new(server => $srv,
                   name => 'my_name_is_glorious',
                   ssl => $use_ssl,
                   SSL_verify_mode => 0);
is $o->info->{connected_clients}, 1;
my $localport = $o->{sock}->sockport;

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

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

done_testing;