root/trunk/api/perl/t/100_flush_bug.t @ 813

Revision 813, 1.2 kB (checked in by ask, 6 months ago)

Enable ReuseAddr

Line 
1#!/usr/bin/env perl -w
2
3use strict;
4use Test::More;
5use Cache::Memcached;
6use IO::Socket::INET;
7
8my $testaddr = "127.0.0.1:11311";
9my $sock = IO::Socket::INET->new(
10    LocalAddr => $testaddr,
11    Proto     => 'tcp',
12    ReuseAddr => 1,
13);
14
15my @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
25if ($sock) {
26    plan tests => scalar @res;
27} else {
28    plan skip_all => "cannot bind to $testaddr\n";
29    exit 0;
30}
31close $sock;
32
33
34my $pid = fork;
35die "Cannot fork because: '$!'" unless defined $pid;
36unless ($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
53my $memd = Cache::Memcached->new({ servers   => [ $testaddr ] });
54
55for (@res) {
56    ($_->[0] =~ s/\W//g);
57    is $memd->flush_all, $_->[1], $_->[0];
58}
Note: See TracBrowser for help on using the browser.