|
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 | |
|---|
| 3 | use strict; |
|---|
| 4 | use Test::More; |
|---|
| 5 | use Cache::Memcached; |
|---|
| 6 | use IO::Socket::INET; |
|---|
| 7 | use Time::HiRes; |
|---|
| 8 | |
|---|
| 9 | my $testaddr = "192.0.2.1:11211"; |
|---|
| 10 | |
|---|
| 11 | plan tests => 2; |
|---|
| 12 | |
|---|
| 13 | my $memd = Cache::Memcached->new({ |
|---|
| 14 | servers => [ $testaddr ], |
|---|
| 15 | namespace => "Cache::Memcached::t/$$/" . (time() % 100) . "/", |
|---|
| 16 | }); |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | my $time1 = Time::HiRes::time(); |
|---|
| 20 | $memd->set("key", "bar"); |
|---|
| 21 | my $time2 = Time::HiRes::time(); |
|---|
| 22 | # 100ms is faster than the default connect timeout. |
|---|
| 23 | ok($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"); |
|---|
| 27 | my $time3 = Time::HiRes::time(); |
|---|
| 28 | ok($time3 - $time2 < .1, "Should return fast on retry"); |
|---|