Skip to content

Commit

Permalink
Fix a bug with session counting for WEBGUI_TEST_DEBUG
Browse files Browse the repository at this point in the history
Store an offset for the session created by the test, which will exist
when initial counts are taken.  And delay final counts as late
as possible, after the session has been closed.  This prevents
a bunch of delta: -1's from showing up.
  • Loading branch information
perlDreamer committed Sep 26, 2009
1 parent 50650c0 commit f53af08
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions t/lib/WebGUI/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ our @EXPORT_OK = qw(session config);
my $CLASS = __PACKAGE__;

my @guarded;
our @checkCount;
our %initCounts;

sub import {
our $CONFIG_FILE = $ENV{ WEBGUI_CONFIG };
Expand All @@ -98,30 +100,22 @@ sub import {
});

if ($ENV{WEBGUI_TEST_DEBUG}) {
my @checkCount = (
Sessions => 'userSession',
Scratch => 'userSessionScratch',
Users => 'users',
Groups => 'groups',
mailQ => 'mailQueue',
Tags => 'assetVersionTag',
Assets => 'assetData',
Workflows => 'Workflow',
##Offset Sessions, and Scratch by 1 because 1 will exist at the start
@checkCount = (
Sessions => userSession => 1,
Scratch => userSessionScratch => 1,
Users => users => 0,
Groups => groups => 0,
mailQ => mailQueue => 0,
Tags => assetVersionTag => 0,
Assets => assetData => 0,
Workflows => Workflow => 0,
);
my %initCounts;
for ( my $i = 0; $i < @checkCount; $i += 2) {
for ( my $i = 0; $i < @checkCount; $i += 3) {
my ($label, $table) = @checkCount[$i, $i+1];
$initCounts{$table} = $session->db->quickScalar('SELECT COUNT(*) FROM ' . $table);
}
push @guarded, Scope::Guard->new(sub {
for ( my $i = 0; $i < @checkCount; $i += 2) {
my ($label, $table) = @checkCount[$i, $i+1];
my $quant = $session->db->quickScalar('SELECT COUNT(*) FROM ' . $table);
my $delta = $quant - $initCounts{$table};
if ($delta) {
$CLASS->builder->diag(sprintf '%-10s: %4d (delta %+d)', $label, $quant, $delta);
}
}
});
}

Expand All @@ -140,7 +134,20 @@ sub cleanup {

if ( my $session = $CLASS->session ) {
$session->var->end;
my $db = delete $session->{_db};
$session->close;
##Do this absolutely last, so that there's no session or other object pieces left over.
if ($ENV{WEBGUI_TEST_DEBUG}) {
for ( my $i = 0; $i < @checkCount; $i += 3) {
my ($label, $table, $offset) = @checkCount[$i, $i+1, $i+2];
my $quant = $db->quickScalar('SELECT COUNT(*) FROM ' . $table);
my $delta = $quant - $initCounts{$table} + $offset;
if ($delta) {
$CLASS->builder->diag(sprintf '%-10s: %4d (delta %+d)', $label, $quant, $delta);
}
}
}
$db->disconnect;
}
}

Expand Down

0 comments on commit f53af08

Please sign in to comment.