4 use Test
::More tests
=> 22;
11 my $builddir = getcwd
;
13 $ENV{'MEMCACHED_PORT_FILENAME'} = "/tmp/ports.$$";
17 open(my $f, "/tmp/ports.$$") || die("Can't open ports file.");
19 my ($type, $port) = split(/:\s+/);
20 $rv{$type} = $port + 0;
22 unlink "/tmp/ports.$$";
27 my ($name, $got, $expected) = @_;
28 # diag "Wanted $expected, got $got";
29 if ($expected == -1) {
30 ok
(!defined($got), "$name expected no port, got $got");
31 } elsif ($expected == 0) {
32 ok
($got != 11211, "$name expected random port (got $got)");
34 is
($got, $expected, "$name");
41 my $exe = "$builddir/memcached-debug";
42 croak
("memcached binary doesn't exist. Haven't run 'make' ?\n") unless -e
$exe;
44 my $childpid = fork();
47 $root = "-u root" if ($< == 0);
48 my $cmd = "$builddir/timedrun 10 $exe $root $args";
56 if (-f
"/tmp/ports.$$") {
57 return Memcached
::Handle
->new(pid
=> $childpid);
59 select undef, undef, undef, 0.10;
61 croak
"Failed to start server.";
65 my ($name, $params, $expected_tcp, $expected_udp) = @_;
67 my $server = run_server
($params);
68 my %ports = read_ports
();
70 validate_port
($name, $ports{'TCP INET'}, $expected_tcp);
71 validate_port
($name, $ports{'UDP INET'}, $expected_udp);
74 # Disabling the defaults since it conflicts with a running instance.
75 # when('no arguments', '', 11211, 11211);
76 when('specifying tcp port', '-p 11212', 11212, 11212);
77 when('specifying udp port', '-U 11222', 11222, 11222);
78 when('specifying tcp ephemeral port', '-p -1', 0, 0);
79 when('specifying udp ephemeral port', '-U -1', 0, 0);
80 when('tcp port disabled', '-p 0', -1, -1);
81 when('udp port disabled', '-U 0', -1, -1);
82 when('specifying tcp and udp ports', '-p 11232 -U 11233', 11232, 11233);
83 when('specifying tcp and disabling udp', '-p 11242 -U 0', 11242, -1);
84 when('specifying udp and disabling tcp', '-p -1 -U 11252', 0, 11252);
85 when('specifying tcp and ephemeral udp', '-p 11262 -U -1', 11262, 0);
86 when('specifying udp and ephemeral tcp', '-p -1 -U 11272', 0, 11272);