~clint-fewbar/+junk/libmemcached-libmemcached-perl

« back to all changes in this revision

Viewing changes to t/60-stats.t

  • Committer: Clint Byrum
  • Date: 2010-06-15 07:16:02 UTC
  • Revision ID: clint@ubuntu.com-20100615071602-kxkor6sd2aadnqek
Initial Release. (LP: #594469)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# tests for functions documented in memcached_stats.pod
 
3
 
 
4
use strict;
 
5
use warnings;
 
6
 
 
7
use Test::More;
 
8
 
 
9
use Memcached::libmemcached
 
10
    #   functions explicitly tested by this file
 
11
    qw(
 
12
    ),
 
13
    #   other functions used by the tests
 
14
    qw(
 
15
        memcached_server_count
 
16
    );
 
17
 
 
18
use lib 't/lib';
 
19
use libmemcached_test;
 
20
 
 
21
my $memc = libmemcached_test_create();
 
22
 
 
23
plan tests => 8;
 
24
 
 
25
ok $memc;
 
26
 
 
27
# walk_stats()
 
28
 
 
29
{
 
30
    # statistics information actually change from version to version,
 
31
    # so we can't even be sure of the number of tests.
 
32
    # We could probably do a version specific testing, but for now
 
33
    # just check that the some constant items/constraints stay constant.
 
34
    my $arg_count_ok = 1;
 
35
    my $keys_defined_ok = 1;
 
36
    my $hostport_defined_ok = 1;
 
37
    my $type_ok = 1;
 
38
    my (%seen_hostport, %seen_distinct);
 
39
    my $walk_stats_rc = $memc->walk_stats("", sub {
 
40
        $arg_count_ok = scalar(@_) == 4 if $arg_count_ok;
 
41
        my ($key, $value, $hostport, $type) = @_;
 
42
        print "$hostport $type: $key=$value\n";
 
43
        $keys_defined_ok = defined $key if $keys_defined_ok;
 
44
        $hostport_defined_ok = defined $hostport if $hostport_defined_ok;
 
45
        $type_ok = defined $type && "" eq $type if $type_ok;
 
46
        $seen_hostport{$hostport} = 1;
 
47
        $seen_distinct{"$hostport:$key"}++;
 
48
        # XXX build $seen_hostport{$hostport} and  it matches memcached_server_count
 
49
        # XXX build hash
 
50
        return;
 
51
    });
 
52
    ok( $walk_stats_rc, "walk_stats should return true");
 
53
    ok( $arg_count_ok, "walk_stats argument count is sane" );
 
54
    ok( $keys_defined_ok, "keys are sane" );
 
55
    ok( $hostport_defined_ok, "hostport are sane" );
 
56
    ok( $type_ok, "types are sane" );
 
57
    is( scalar keys %seen_hostport, memcached_server_count($memc),
 
58
        "should see responses from each server");
 
59
    is( scalar (grep { $_ != 1 } values %seen_distinct), 0,
 
60
        "should see no distinct hostport+key more than once");
 
61
}