Skip to content

Commit

Permalink
Fix up some tests
Browse files Browse the repository at this point in the history
Planning on removing the associative feature at some point soon
  • Loading branch information
jonathanstowe committed Feb 8, 2019
1 parent a18e25c commit a17d7ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/Cache/Memcached.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -603,10 +603,12 @@ class Cache::Memcached:auth<cosimo>:ver<0.0.11> does Associative {
my @keys; my @keys;
my $ns = $!namespace; my $ns = $!namespace;
for @!buckets.map({ self.sock-to-host($_) }).grep({ .defined }) -> $sock { for @!buckets.map({ self.sock-to-host($_) }).grep({ .defined }) -> $sock {
self.write-and-read($sock, "stats items\r\n");
for self.slab-numbers -> $slab { for self.slab-numbers -> $slab {
my $lines = self.write-and-read($sock, "stats cachedump $slab 0\r\n", -> $bref { self.log-debug("SLAB: $slab");
return $bref ~~ /:m^[END|ERROR]\r?\n/; my $lines = self.write-and-read($sock, "stats cachedump $slab 0\r\n");
}); self.log-debug("NS: $ns");
self.log-debug("LINES: $lines");


if $lines ~~ m:global/^^'ITEM ' $ns$<key> = [ \S+ ]/ { if $lines ~~ m:global/^^'ITEM ' $ns$<key> = [ \S+ ]/ {
for $/.list -> $item { for $/.list -> $item {
Expand Down
13 changes: 11 additions & 2 deletions t/00900-associative.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ my $testaddr = "127.0.0.1";
my $port = 11211; my $port = 11211;


if not check-socket($port, "127.0.0.1") { if not check-socket($port, "127.0.0.1") {
plan 1;
skip-rest "no memcached server"; skip-rest "no memcached server";
exit; exit;


Expand All @@ -17,6 +18,7 @@ if not check-socket($port, "127.0.0.1") {
my $memd = Cache::Memcached.new( my $memd = Cache::Memcached.new(
servers => [ "$testaddr:$port" ], servers => [ "$testaddr:$port" ],
namespace => "Cache::Memcached::t/$*PID/" ~ (now % 100) ~ "/", namespace => "Cache::Memcached::t/$*PID/" ~ (now % 100) ~ "/",
debug => so %*ENV<MDEBUG>,
); );


lives-ok { $memd<test-test-key> = "test value" }, "set as associative"; lives-ok { $memd<test-test-key> = "test value" }, "set as associative";
Expand All @@ -25,10 +27,17 @@ is $memd<test-test-key>, "test value" , "and got the right value back";
is $memd<test-test-key>:delete, "test value" , "delete key and get the right value back"; is $memd<test-test-key>:delete, "test value" , "delete key and get the right value back";
nok $memd<test-test-key>:exists, "and it no longer exists"; nok $memd<test-test-key>:exists, "and it no longer exists";


for <foo bar baz> -> $key { my %data = foo => (^1000).pick, bar => (^1000).pick, baz => (^1000).pick;
$memd{$key} = (^1000).pick;
for %data.pairs -> $pair {
$memd{$pair.key} = $pair.value;
ok $memd{$pair.key}:exists, "added { $pair }";
} }


my @keys = %data.keys;

ok so all(@keys) $memd.keys.list, 'keys returns the keys we expected';

for $memd.keys -> $key { for $memd.keys -> $key {
ok $memd{$key}:exists, "key $key exists"; ok $memd{$key}:exists, "key $key exists";
} }
Expand Down

0 comments on commit a17d7ec

Please sign in to comment.