diff options
author | dormando <dormando@rydia.net> | 2017-07-26 15:08:48 -0700 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2017-07-26 15:08:48 -0700 |
commit | c1e854a836179e2095bde1180f7e8ebfa0976f78 (patch) | |
tree | 3809c1c16e9671daaeaad3095878028669e4f215 /t/lib | |
parent | 24ca3d89b0e3fd2e4a11301ae3f37ee872567620 (diff) | |
download | memcached-c1e854a836179e2095bde1180f7e8ebfa0976f78.tar.gz |
default to unix sockets for tests
Tests have randomly failed to start since the beginning of time, due largely
to port assignment. A random local port is tested, then passed onto the daemon
to try. If that port (on 0.0.0.0) becomes used in the meantime, it fails.
Now, tests default to using unix sockets unique to the pid of the test parent.
Some tests still run via the network and have been changed to 127.0.0.1, which
should collide less with normal internet connections. Some tests require that
due to some timing issues that unix sockets seem to create, and others expect
a network in a few cases.
Ran the tests with `PARALLEL=9 make test` on my machine for two hours and they
didn't fail once.
Diffstat (limited to 't/lib')
-rw-r--r-- | t/lib/MemcachedTest.pm | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/t/lib/MemcachedTest.pm b/t/lib/MemcachedTest.pm index 88f37a2..d78ad42 100644 --- a/t/lib/MemcachedTest.pm +++ b/t/lib/MemcachedTest.pm @@ -11,6 +11,7 @@ use vars qw(@EXPORT); use Cwd; my $builddir = getcwd; +my @unixsockets = (); @EXPORT = qw(new_memcached sleep mem_get_is mem_gets mem_gets_is mem_stats supports_sasl free_port); @@ -150,7 +151,7 @@ sub supports_sasl { sub new_memcached { my ($args, $passed_port) = @_; - my $port = $passed_port || free_port(); + my $port = $passed_port; my $host = '127.0.0.1'; if ($ENV{T_MEMD_USE_DAEMON}) { @@ -164,13 +165,22 @@ sub new_memcached { croak("Failed to connect to specified memcached server.") unless $conn; } - my $udpport = free_port("udp"); - $args .= " -p $port"; - if (supports_udp()) { - $args .= " -U $udpport"; - } - if ($< == 0) { - $args .= " -u root"; + my $udpport; + if ($args =~ /-l (\S+)/) { + $port = free_port(); + $udpport = free_port("udp"); + $args .= " -p $port"; + if (supports_udp()) { + $args .= " -U $udpport"; + } + if ($< == 0) { + $args .= " -u root"; + } + } elsif ($args !~ /-s (\S+)/) { + my $num = @unixsockets; + my $file = "/tmp/memcachetest.$$.$num"; + $args .= " -s $file"; + push(@unixsockets, $file); } my $childpid = fork(); @@ -215,6 +225,12 @@ sub new_memcached { croak("Failed to startup/connect to memcached server."); } +END { + for (@unixsockets) { + unlink $_; + } +} + ############################################################################ package Memcached::Handle; sub new { |