root/trunk/api/perl/t/05_reconnect_timeout.t @ 805

Revision 805, 0.7 kB (checked in by hachi, 11 months ago)

Fix reconnects on dead sockets to not be as slow.

Line 
1#!/usr/bin/env perl -w
2
3use strict;
4use Test::More;
5use Cache::Memcached;
6use IO::Socket::INET;
7use Time::HiRes;
8
9my $testaddr = "192.0.2.1:11211";
10
11plan tests => 2;
12
13my $memd = Cache::Memcached->new({
14    servers   => [ $testaddr ],
15    namespace => "Cache::Memcached::t/$$/" . (time() % 100) . "/",
16});
17
18
19my $time1 = Time::HiRes::time();
20$memd->set("key", "bar");
21my $time2 = Time::HiRes::time();
22# 100ms is faster than the default connect timeout.
23ok($time2 - $time1 > .1, "Expected pause while connecting");
24
25# 100ms should be slow enough that dead socket reconnects happen faster than it.
26$memd->set("key", "foo");
27my $time3 = Time::HiRes::time();
28ok($time3 - $time2 < .1, "Should return fast on retry");
Note: See TracBrowser for help on using the browser.