clean up some parts of WebGUI::Test
This commit is contained in:
parent
7f820d9f35
commit
b8aac77501
1 changed files with 32 additions and 32 deletions
|
|
@ -73,8 +73,6 @@ our @EXPORT_OK = qw(session config);
|
||||||
|
|
||||||
my $CLASS = __PACKAGE__;
|
my $CLASS = __PACKAGE__;
|
||||||
|
|
||||||
my @guarded;
|
|
||||||
|
|
||||||
sub import {
|
sub import {
|
||||||
our $CONFIG_FILE = $ENV{ WEBGUI_CONFIG };
|
our $CONFIG_FILE = $ENV{ WEBGUI_CONFIG };
|
||||||
|
|
||||||
|
|
@ -91,7 +89,7 @@ sub import {
|
||||||
my $session = our $SESSION = $CLASS->newSession(1);
|
my $session = our $SESSION = $CLASS->newSession(1);
|
||||||
|
|
||||||
my $originalSetting = clone $session->setting->get;
|
my $originalSetting = clone $session->setting->get;
|
||||||
push @guarded, Scope::Guard->new(sub {
|
$CLASS->addToCleanup(sub {
|
||||||
while (my ($param, $value) = each %{ $originalSetting }) {
|
while (my ($param, $value) = each %{ $originalSetting }) {
|
||||||
$session->setting->set($param, $value);
|
$session->setting->set($param, $value);
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +123,7 @@ sub import {
|
||||||
my ($label, $table) = @checkCount[$i, $i+1];
|
my ($label, $table) = @checkCount[$i, $i+1];
|
||||||
$initCounts{$table} = $session->db->quickScalar('SELECT COUNT(*) FROM ' . $table);
|
$initCounts{$table} = $session->db->quickScalar('SELECT COUNT(*) FROM ' . $table);
|
||||||
}
|
}
|
||||||
push @guarded, Scope::Guard->new(sub {
|
$CLASS->addToCleanup(sub {
|
||||||
for ( my $i = 0; $i < @checkCount; $i += 2) {
|
for ( my $i = 0; $i < @checkCount; $i += 2) {
|
||||||
my ($label, $table) = @checkCount[$i, $i+1];
|
my ($label, $table) = @checkCount[$i, $i+1];
|
||||||
my $quant = $session->db->quickScalar('SELECT COUNT(*) FROM ' . $table);
|
my $quant = $session->db->quickScalar('SELECT COUNT(*) FROM ' . $table);
|
||||||
|
|
@ -144,19 +142,6 @@ END {
|
||||||
$CLASS->cleanup;
|
$CLASS->cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cleanup {
|
|
||||||
# remove guards in reverse order they were added, triggering all of the
|
|
||||||
# requested cleanup operations
|
|
||||||
pop @guarded
|
|
||||||
while @guarded;
|
|
||||||
|
|
||||||
if ( our $SESSION ) {
|
|
||||||
$SESSION->var->end;
|
|
||||||
$SESSION->close;
|
|
||||||
undef $SESSION;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 newSession ( $noCleanup )
|
=head2 newSession ( $noCleanup )
|
||||||
|
|
@ -175,7 +160,7 @@ sub newSession {
|
||||||
my $session = WebGUI::Session->open( $CLASS->root, $CLASS->file );
|
my $session = WebGUI::Session->open( $CLASS->root, $CLASS->file );
|
||||||
$session->{_request} = $pseudoRequest;
|
$session->{_request} = $pseudoRequest;
|
||||||
if ( ! $noCleanup ) {
|
if ( ! $noCleanup ) {
|
||||||
$CLASS->sessionsToDelete($session);
|
$CLASS->addToCleanup($session);
|
||||||
}
|
}
|
||||||
return $session;
|
return $session;
|
||||||
}
|
}
|
||||||
|
|
@ -558,7 +543,7 @@ sub prepareMailServer {
|
||||||
# Let it start up yo
|
# Let it start up yo
|
||||||
sleep 2;
|
sleep 2;
|
||||||
|
|
||||||
push @guarded, Scope::Guard->new(sub {
|
$CLASS->addToCleanup(sub {
|
||||||
# Close SMTPD
|
# Close SMTPD
|
||||||
if ($smtpdPid) {
|
if ($smtpdPid) {
|
||||||
kill INT => $smtpdPid;
|
kill INT => $smtpdPid;
|
||||||
|
|
@ -591,7 +576,7 @@ sub originalConfig {
|
||||||
}
|
}
|
||||||
# add cleanup handler if this is the first time we were run
|
# add cleanup handler if this is the first time we were run
|
||||||
if (! keys %originalConfig) {
|
if (! keys %originalConfig) {
|
||||||
push @guarded, Scope::Guard->new(sub {
|
$class->addToCleanup(sub {
|
||||||
while (my ($key, $value) = each %originalConfig) {
|
while (my ($key, $value) = each %originalConfig) {
|
||||||
if (defined $value) {
|
if (defined $value) {
|
||||||
$CLASS->session->config->set($key, $value);
|
$CLASS->session->config->set($key, $value);
|
||||||
|
|
@ -661,6 +646,7 @@ sub getMailFromQueue {
|
||||||
|
|
||||||
return $class->getMail;
|
return $class->getMail;
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 sessionsToDelete ( $session, [$session, ...] )
|
=head2 sessionsToDelete ( $session, [$session, ...] )
|
||||||
|
|
@ -675,7 +661,7 @@ This is a class method.
|
||||||
|
|
||||||
sub sessionsToDelete {
|
sub sessionsToDelete {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
push @guarded, cleanupGuard(@_);
|
$class->addToCleanup(@_);
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -692,7 +678,7 @@ This is a class method.
|
||||||
|
|
||||||
sub assetsToPurge {
|
sub assetsToPurge {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
push @guarded, cleanupGuard(@_);
|
$class->addToCleanup(@_);
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -727,7 +713,7 @@ This is a class method.
|
||||||
|
|
||||||
sub groupsToDelete {
|
sub groupsToDelete {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
push @guarded, cleanupGuard(@_);
|
$class->addToCleanup(@_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -744,7 +730,7 @@ This is a class method.
|
||||||
|
|
||||||
sub storagesToDelete {
|
sub storagesToDelete {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
push @guarded, cleanupGuard(map {
|
$class->addToCleanup(map {
|
||||||
ref $_ ? $_ : ('WebGUI::Storage' => $_)
|
ref $_ ? $_ : ('WebGUI::Storage' => $_)
|
||||||
} @_);
|
} @_);
|
||||||
}
|
}
|
||||||
|
|
@ -761,7 +747,7 @@ This is a class method.
|
||||||
|
|
||||||
sub tagsToRollback {
|
sub tagsToRollback {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
push @guarded, cleanupGuard(@_);
|
$class->addToCleanup(@_);
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -777,7 +763,7 @@ This is a class method.
|
||||||
|
|
||||||
sub usersToDelete {
|
sub usersToDelete {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
push @guarded, cleanupGuard(@_);
|
$class->addToCleanup(@_);
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -793,7 +779,7 @@ This is a class method.
|
||||||
|
|
||||||
sub workflowsToDelete {
|
sub workflowsToDelete {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
push @guarded, cleanupGuard(@_);
|
$class->addToCleanup(@_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1029,12 +1015,26 @@ This is a class method.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
my @guarded;
|
||||||
sub addToCleanup {
|
sub addToCleanup {
|
||||||
shift
|
shift
|
||||||
if eval { $_[0]->isa($CLASS) };
|
if eval { $_[0]->isa($CLASS) };
|
||||||
push @guarded, cleanupGuard(@_);
|
push @guarded, cleanupGuard(@_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub cleanup {
|
||||||
|
# remove guards in reverse order they were added, triggering all of the
|
||||||
|
# requested cleanup operations
|
||||||
|
pop @guarded
|
||||||
|
while @guarded;
|
||||||
|
|
||||||
|
if ( our $SESSION ) {
|
||||||
|
$SESSION->var->end;
|
||||||
|
$SESSION->close;
|
||||||
|
undef $SESSION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head1 BUGS
|
=head1 BUGS
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue