File: 02_fork.t

package info (click to toggle)
libcache-memcached-fast-safe-perl 0.06-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 120 kB
  • sloc: perl: 125; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 991 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
use strict;
use warnings;
use Test::More;

use Test::TCP qw/empty_port wait_port/;
use Test::Skip::UnlessExistsExecutable;
use File::Which qw(which);
use Proc::Guard;
use Cache::Memcached::Fast::Safe;
use POSIX qw//;
#use Log::Minimal;
#$Log::Minimal::AUTODUMP =1;

skip_all_unless_exists 'memcached';

my @memcached;
my @user = ();
if ( $> == 0 ) {
    @user = ('-u','nobody');
}

for ( 1..5 ) {
    my $port = empty_port();
    my $proc = proc_guard( scalar which('memcached'), '-p', $port, '-U', 0, '-l', '127.0.0.1', @user );
    wait_port($port);
    push @memcached, { proc => $proc, port => $port };
}

my $cache = Cache::Memcached::Fast::Safe->new({
    servers => [map { "localhost:" . $_->{port} } @memcached],
});
my $version = $cache->server_versions;

my $pid = fork;
if ( $pid == 0 ) {
    my $after_fork = $cache->server_versions; 
    is_deeply($after_fork, $version);
    POSIX::_exit(0);
}

waitpid($pid,0);
is_deeply($cache->server_versions, $version);

done_testing();