Skip to content

Commit

Permalink
Issue #87: make the END block a closure
Browse files Browse the repository at this point in the history
Less action at a distance.
  • Loading branch information
bschmalhofer committed Jul 1, 2020
1 parent bce3243 commit 18d1d4f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Kernel/System/UnitTest/RegisterDriver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@ use warnings;
# OTOBO modules
use Kernel::System::ObjectManager;

my $OriginalPID; # see the END block

sub import {

# remember the id of the process that loaded this module.
$OriginalPID = $$;

# RegisterDriver is meant for test scripts,
# meaning that each sript has it's own process.
# This means that we don't have to localize $Kernel::OM.
Expand All @@ -72,19 +67,24 @@ sub import {
return;
}

END {
# Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker, and maybe other modules, is forking processes.
# But we want no cleanup in the child processes.
if ( $$ == $OriginalPID ) {
# trigger Kernel::System::UnitTest::Helper::DESTROY()
# perform cleanup actions, including some tests, in Kernel::System::UnitTest::Helper::DESTROY
$Kernel::OM->ObjectsDiscard(
Objects => ['Kernel::System::UnitTest::Helper'],
);

# print the plan
my $Driver = $Kernel::OM->Get( 'Kernel::System::UnitTest::Driver' );
$Driver->DoneTesting();
{
# remember the id of the process that loaded this module.
my $OriginalPID = $$;

END {
# Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker, and maybe other modules, is forking processes.
# But we want no cleanup in the child processes.
if ( $$ == $OriginalPID ) {
# trigger Kernel::System::UnitTest::Helper::DESTROY()
# perform cleanup actions, including some tests, in Kernel::System::UnitTest::Helper::DESTROY
$Kernel::OM->ObjectsDiscard(
Objects => ['Kernel::System::UnitTest::Helper'],
);

# print the test plan
my $Driver = $Kernel::OM->Get( 'Kernel::System::UnitTest::Driver' );
$Driver->DoneTesting();
}
}
}

Expand Down

0 comments on commit 18d1d4f

Please sign in to comment.