Skip to content

Commit

Permalink
proxy: let tests use unix socket for proxy daemon
Browse files Browse the repository at this point in the history
A long sleep in the unix startup code made backends hit the connection
timeout before the backends were configured.

Make all the proxy tests use the unix socket instead of listening on a
hardcoded port. Proxy code is completely equivalent from the client
standpoint.

This fix should make the whole test suite run a bit faster too.
  • Loading branch information
dormando committed Apr 28, 2023
1 parent 24bf90c commit 6350e44
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions t/lib/MemcachedTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ sub new_memcached {
# A slow/emulated/valgrinded/etc system may take longer than a second
# for the unix socket to appear.
my $filename = $1;
for (1..20) {
sleep 1;
for (1..60) {
my $conn = IO::Socket::UNIX->new(Peer => $filename);

if ($conn) {
Expand All @@ -364,7 +363,7 @@ sub new_memcached {
port => $port);
} else {
croak("Failed to connect to unix socket: memcached not running") unless is_running($childpid);
sleep 1;
select undef, undef, undef, 0.20;
}
}
croak("Failed to connect to unix domain socket: $! '$filename'") if $@;
Expand Down
2 changes: 1 addition & 1 deletion t/proxy.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for (2 .. 6) {
}
#my $sock = $srv->sock;

my $p_srv = new_memcached('-o proxy_config=./t/startfile.lua -l 127.0.0.1', 11211);
my $p_srv = new_memcached('-o proxy_config=./t/startfile.lua');
my $p_sock = $p_srv->sock;

# hack to help me use T_MEMD_USE_DAEMON for proxy.
Expand Down
4 changes: 2 additions & 2 deletions t/proxyconfig.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ for my $port (11511, 11512, 11513) {
diag "testing failure to start";
write_modefile("invalid syntax");
eval {
my $p_srv = new_memcached('-o proxy_config=./t/proxyconfig.lua -l 127.0.0.1', 11510);
my $p_srv = new_memcached('-o proxy_config=./t/proxyconfig.lua');
};
ok($@ && $@ =~ m/Failed to connect/, "server successfully not started");

write_modefile('return "none"');
my $p_srv = new_memcached('-o proxy_config=./t/proxyconfig.lua -l 127.0.0.1', 11510);
my $p_srv = new_memcached('-o proxy_config=./t/proxyconfig.lua');
my $ps = $p_srv->sock;
$ps->autoflush(1);

Expand Down
2 changes: 1 addition & 1 deletion t/proxyinternal.t
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ for my $port (11611, 11612, 11613) {
push(@mocksrvs, $srv);
}

my $p_srv = new_memcached("-o proxy_config=./t/proxyinternal.lua,ext_item_size=500,ext_item_age=1,ext_path=$ext_path:64m,ext_max_sleep=100000 -l 127.0.0.1 -U 0", 11510);
my $p_srv = new_memcached("-o proxy_config=./t/proxyinternal.lua,ext_item_size=500,ext_item_age=1,ext_path=$ext_path:64m,ext_max_sleep=100000");
my $ps = $p_srv->sock;
$ps->autoflush(1);

Expand Down
2 changes: 1 addition & 1 deletion t/proxyunits.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ for my $port (11411, 11412, 11413) {
push(@mocksrvs, $srv);
}

my $p_srv = new_memcached('-o proxy_config=./t/proxyunits.lua -l 127.0.0.1', 11410);
my $p_srv = new_memcached('-o proxy_config=./t/proxyunits.lua');
my $ps = $p_srv->sock;
$ps->autoflush(1);

Expand Down

0 comments on commit 6350e44

Please sign in to comment.