File: 07-lazy-conn.t

package info (click to toggle)
libanyevent-riperedis-perl 0.48-3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 1,430; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use 5.008000;
use strict;
use warnings;

use Test::More;
use AnyEvent::RipeRedis;
require 't/test_helper.pl';

my $SERVER_INFO = run_redis_instance();
if ( !defined $SERVER_INFO ) {
  plan skip_all => 'redis-server is required for this test';
}
plan tests => 2;

my $T_CONNECTED = 0;

my $redis;

ev_loop(
  sub {
    my $cv = shift;

    $redis = AnyEvent::RipeRedis->new(
      host       => $SERVER_INFO->{host},
      port       => $SERVER_INFO->{port},
      lazy       => 1,
      reconnect  => 0,

      on_connect => sub {
        $T_CONNECTED = 1;
      },
    );

    my $timer;
    $timer = AnyEvent->timer(
      after => 3,
      cb    => sub {
        undef $timer;

        ok( !$T_CONNECTED, 'lazy connection (no connected yet)' );

        $redis->ping(
          sub {
            my $reply = shift;
            my $err   = shift;

            if ( defined $err ) {
              diag( $err->message );
            }

            $cv->send;
          }
        );
      },
    );
  }
);

ok( $T_CONNECTED, 'lazy connection (connected)' );