| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Memcached
Revision: 790
Author: ykerherve
Date: 23 Jul 2008 15:18:17
Changes:Fixed flush_all to only return success when there is a proper OK
returned by all the servers.
| ... | ...@@ -0,0 +1,58 @@ | |
| 1 | #!/usr/bin/env perl -w | |
| 2 | ||
| 3 | use strict; | |
| 4 | use Test::More; | |
| 5 | use Cache::Memcached; | |
| 6 | use IO::Socket::INET; | |
| 7 | ||
| 8 | my $testaddr = "127.0.0.1:11311"; | |
| 9 | my $sock = IO::Socket::INET->new( | |
| 10 | LocalAddr => $testaddr, | |
| 11 | Proto => 'tcp', | |
| 12 | ReusAddr => 1, | |
| 13 | ); | |
| 14 | ||
| 15 | my @res = ( | |
| 16 | ["OK\r\n", 1], | |
| 17 | ["ERROR\r\n", 0], | |
| 18 | ["\r\nERROR\r\n", 0], | |
| 19 | ["FOO\r\nERROR\r\n", 0], | |
| 20 | ["FOO\r\nOK\r\nERROR\r\n", 0], | |
| 21 | ["\r\n\r\nOK\r\n", 0], | |
| 22 | ["END\r\n", 0], | |
| 23 | ); | |
| 24 | ||
| 25 | if ($sock) { | |
| 26 | plan tests => scalar @res; | |
| 27 | } else { | |
| 28 | plan skip_all => "cannot bind to $testaddr\n"; | |
| 29 | exit 0; | |
| 30 | } | |
| 31 | close $sock; | |
| 32 | ||
| 33 | ||
| 34 | my $pid = fork; | |
| 35 | die "Cannot fork because: '$!'" unless defined $pid; | |
| 36 | unless ($pid) { | |
| 37 | my $sock = IO::Socket::INET->new( | |
| 38 | LocalAddr => $testaddr, | |
| 39 | Proto => 'tcp', | |
| 40 | ReusAddr => 1, | |
| 41 | Listen => 1, | |
| 42 | ) or die "cannot open $testaddr: $!"; | |
| 43 | my $csock = $sock->accept(); | |
| 44 | while (defined (my $buf = <$csock>)) { | |
| 45 | my $res = shift @res; | |
| 46 | print $csock $res->[0]; | |
| 47 | } | |
| 48 | close $csock; | |
| 49 | close $sock; | |
| 50 | exit 0; | |
| 51 | } | |
| 52 | ||
| 53 | my $memd = Cache::Memcached->new({ servers => [ $testaddr ] }); | |
| 54 | ||
| 55 | for (@res) { | |
| 56 | ($_->[0] =~ s/\W//g); | |
| 57 | is $memd->flush_all, $_->[1], $_->[0]; | |
| 58 | } |
| ... | ...@@ -1,3 +1,6 @@ | |
| 1 | * flush_all now only returns success if there is a proper reply from all | |
| 2 | servers - Yann Kerherve <yann@sixapart.com> | |
| 3 | ||
| 1 | 4 | * 'noreply' support from Tomash Brechko <tomash.brechko@gmail.com> |
| 2 | 5 | |
| 3 | 6 | * various test updates from Ronald J Kimball <rkimball@pangeamedia.com> |
| ... | ...@@ -783,7 +783,7 @@ | |
| 783 | 783 | foreach my $host (@hosts) { |
| 784 | 784 | my $sock = $self->sock_to_host($host); |
| 785 | 785 | my @res = $self->run_command($sock, "flush_all\r\n"); |
| 786 | $success = 0 unless (@res); | |
| 786 | $success = 0 unless (scalar @res == 1 && (($res[0] || "") eq "OK\r\n")); | |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | return $success; |