File: 31stats.t

package info (click to toggle)
libdbix-class-perl 0.08010-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,052 kB
  • ctags: 1,064
  • sloc: perl: 10,536; sql: 225; makefile: 45
file content (109 lines) | stat: -rwxr-xr-x 2,110 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;

BEGIN {
    eval "use DBD::SQLite";
    plan $@
        ? ( skip_all => 'needs DBD::SQLite for testing' )
        : ( tests => 12 );
}

use lib qw(t/lib);

use_ok('DBICTest');
my $schema = DBICTest->init_schema();

my $cbworks = 0;

$schema->storage->debugcb(sub { $cbworks = 1; });
$schema->storage->debug(0);
my $rs = $schema->resultset('CD')->search({});
$rs->count();
ok(!$cbworks, 'Callback not called with debug disabled');

$schema->storage->debug(1);

$rs->count();
ok($cbworks, 'Debug callback worked.');

my $prof = new DBIx::Test::Profiler();
$schema->storage->debugobj($prof);

# Test non-transaction calls.
$rs->count();
ok($prof->{'query_start'}, 'query_start called');
ok($prof->{'query_end'}, 'query_end called');
ok(!$prof->{'txn_begin'}, 'txn_begin not called');
ok(!$prof->{'txn_commit'}, 'txn_commit not called');

$prof->reset();

# Test transaction calls
$schema->txn_begin();
ok($prof->{'txn_begin'}, 'txn_begin called');

$rs = $schema->resultset('CD')->search({});
$rs->count();
ok($prof->{'query_start'}, 'query_start called');
ok($prof->{'query_end'}, 'query_end called');

$schema->txn_commit();
ok($prof->{'txn_commit'}, 'txn_commit called');

$prof->reset();

# Test a rollback
$schema->txn_begin();
$rs = $schema->resultset('CD')->search({});
$rs->count();
$schema->txn_rollback();
ok($prof->{'txn_rollback'}, 'txn_rollback called');

$schema->storage->debug(0);

package DBIx::Test::Profiler;
use strict;

sub new {
    my $self = bless({});
}

sub query_start {
    my $self = shift();
    $self->{'query_start'} = 1;
}

sub query_end {
    my $self = shift();
    $self->{'query_end'} = 1;
}

sub txn_begin {
    my $self = shift();
    $self->{'txn_begin'} = 1;
}

sub txn_rollback {
    my $self = shift();
    $self->{'txn_rollback'} = 1;
}

sub txn_commit {
    my $self = shift();
    $self->{'txn_commit'} = 1;
}

sub reset {
    my $self = shift();

    $self->{'query_start'} = 0;
    $self->{'query_end'} = 0;
    $self->{'txn_begin'} = 0;
    $self->{'txn_rollback'} = 0;
    $self->{'txn_end'} = 0;
}

1;