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 | |
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')
-rwxr-xr-x | t/binary.t | 2 | ||||
-rwxr-xr-x | t/expirations.t | 4 | ||||
-rw-r--r-- | t/idle-timeout.t | 2 | ||||
-rw-r--r-- | t/lib/MemcachedTest.pm | 32 | ||||
-rw-r--r-- | t/lru-maintainer.t | 4 | ||||
-rwxr-xr-x | t/stats-conns.t | 3 | ||||
-rwxr-xr-x | t/stats.t | 2 | ||||
-rwxr-xr-x | t/udp.t | 2 |
8 files changed, 34 insertions, 17 deletions
@@ -436,7 +436,7 @@ $mc->silent_mutation(::CMD_ADDQ, 'silentadd', 'silentaddval'); my %stats = $mc->stats('settings'); is(1024, $stats{'maxconns'}); - is('NULL', $stats{'domain_socket'}); + isnt('NULL', $stats{'domain_socket'}); is('on', $stats{'evictions'}); is('yes', $stats{'cas_enabled'}); is('yes', $stats{'flush_enabled'}); diff --git a/t/expirations.t b/t/expirations.t index c92125a..47300cb 100755 --- a/t/expirations.t +++ b/t/expirations.t @@ -28,11 +28,11 @@ sub wait_for_early_second { wait_for_early_second(); -print $sock "set foo 0 1 6\r\nfooval\r\n"; +print $sock "set foo 0 3 6\r\nfooval\r\n"; is(scalar <$sock>, "STORED\r\n", "stored foo"); mem_get_is($sock, "foo", "fooval"); -sleep(1.5); +sleep(4); mem_get_is($sock, "foo", undef); $expire = time() - 1; diff --git a/t/idle-timeout.t b/t/idle-timeout.t index bcd8188..66558ac 100644 --- a/t/idle-timeout.t +++ b/t/idle-timeout.t @@ -10,7 +10,7 @@ use lib "$Bin/lib"; use MemcachedTest; # start up a server with 10 maximum connections -my $server = new_memcached("-o idle_timeout=3"); +my $server = new_memcached("-o idle_timeout=3 -l 127.0.0.1"); my $sock = $server->sock; # Make sure we can talk to start with 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 { diff --git a/t/lru-maintainer.t b/t/lru-maintainer.t index 63b1c27..ac2ba7b 100644 --- a/t/lru-maintainer.t +++ b/t/lru-maintainer.t @@ -9,7 +9,7 @@ use MemcachedTest; # Regression test for underestimating the size of items after the large memory # change. -my $server = new_memcached('-m 3 -o lru_maintainer,lru_crawler'); +my $server = new_memcached('-m 3 -o lru_maintainer,lru_crawler -l 127.0.0.1'); my $sock = $server->sock; my $keystub = "X"x200; for (1 .. 15000) { @@ -21,7 +21,7 @@ print $sock "set $keystub 0 0 2\r\nok\r\n"; is(scalar <$sock>, "STORED\r\n", "stored key without OOM"); # Basic tests -$server = new_memcached('-m 6 -o lru_maintainer,lru_crawler'); +$server = new_memcached('-m 6 -o lru_maintainer,lru_crawler -l 127.0.0.1'); $sock = $server->sock; for (1 .. 10) { diff --git a/t/stats-conns.t b/t/stats-conns.t index 83f6c73..4dc6554 100755 --- a/t/stats-conns.t +++ b/t/stats-conns.t @@ -50,7 +50,7 @@ unlink($filename); ## Now look at TCP -$server = new_memcached(); +$server = new_memcached("-l 0.0.0.0"); $sock = $server->sock; $stats_sock = $server->new_sock; @@ -67,4 +67,5 @@ like($stats, qr/STAT \d+:state conn_listen/, "there is a listen socket"); $stats =~ m/STAT \d+:addr udp:0.0.0.0:(\d+)/; is($1, $server->udpport, "udp port number is correct"); $stats =~ m/STAT \d+:addr tcp:0.0.0.0:(\d+)/; +print STDERR "PORT: ", $server->port, "\n"; is($1, $server->port, "tcp port number is correct"); @@ -130,7 +130,7 @@ is('z', $v, 'got the expected value'); my $settings = mem_stats($sock, ' settings'); is(1024, $settings->{'maxconns'}); -is('NULL', $settings->{'domain_socket'}); +isnt('NULL', $settings->{'domain_socket'}); is('on', $settings->{'evictions'}); is('yes', $settings->{'cas_enabled'}); is('no', $settings->{'auth_enabled_sasl'}); @@ -27,7 +27,7 @@ use constant INCRDECR_PKT_FMT => "NNNNN"; use constant MIN_RECV_BYTES => length(pack(RES_PKT_FMT)); -my $server = new_memcached(); +my $server = new_memcached("-l 127.0.0.1"); my $sock = $server->sock; # set foo (and should get it) |