File: 06-on-connect.t

package info (click to toggle)
libredis-fast-perl 0.22%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 488 kB
  • sloc: perl: 2,539; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 977 bytes parent folder | download | duplicates (3)
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
#!perl

use warnings;
use strict;
use Test::More;
use Test::Fatal;
use Redis::Fast;
use lib 't/tlib';
use Test::SpawnRedisServer;

my ($c, $srv) = redis(timeout => 1);
END { $c->() if $c }

subtest 'on_connect' => sub {
  my $r;
  ok($r = Redis::Fast->new(server => $srv, on_connect => sub { shift->incr('on_connect') }),
    'connected to our test redis-server');
  is($r->get('on_connect'), 1, '... on_connect code was run');

  ok($r = Redis::Fast->new(server => $srv, on_connect => sub { shift->incr('on_connect') }),
    'new connection is up and running');
  is($r->get('on_connect'), 2, '... on_connect code was run again');

  ok($r = Redis::Fast->new(reconnect => 1, server => $srv, on_connect => sub { shift->incr('on_connect') }),
    'new connection with reconnect enabled');
  is($r->get('on_connect'), 3, '... on_connect code one again perfect');

  $r->quit;
  is($r->get('on_connect'), 4, '... on_connect code works after reconnect also');
};


done_testing();