File: 08-unix-socket.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 (48 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (4)
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
#!perl

use warnings;
use strict;
use Test::More;
use Test::Fatal;
use Redis::Fast;

plan skip_all => 'Define ENV TEST_REDIS_SERVER_SOCK_PATH to test UNIX socket support'
  unless $ENV{TEST_REDIS_SERVER_SOCK_PATH};

my $conn = sub {
  my @args = @_;

  my $r;
  is(
    exception {
      $r = Redis::Fast->new(sock => $ENV{TEST_REDIS_SERVER_SOCK_PATH}, @args);
    },
    undef,
    'Connected to the Redis server ok',
  );

  return $r;
};


subtest 'basic tests' => sub {
  my $r = $conn->();

  ok($r->set(xpto => '42'), '... set command via UNIX ok');
  is($r->get('xpto'), '42', '... and get command ok too');

  is(exception { $r->quit }, undef, 'Connection closed ok');
  like(exception { $r->get('xpto') }, qr!Not connected to any server!, 'Command failed ok, no reconnect',);
};


subtest 'reconnect over UNIX daemon' => sub {
  my $r = $conn->(reconnect => 2);
  ok($r->quit, '... and connection closed ok');

  is(exception { $r->set(xpto => '43') }, undef, 'set command via UNIX ok, reconnected fine');
  is($r->get('xpto'), '43', '... and get command ok too');
};


done_testing();