Skip to content

Commit a566436

Browse files
George S. Baughtoddr
authored andcommitted
Don't confuse callers by returning a failure if plugin already included
Case CPANEL-22183: It's common practice to do: cPanel::TaskQueue::PluginManager::load_plugin_by_name(...) or ... And it can't reasonably be considered that skipping setup because it is already setup is a *failure* condition. Ergo, we make it into a success condition. This will fix a number of existing callers making this assumption incorrectly. Changelog: Make plugin include return true when plugins are already included.
1 parent 858692e commit a566436

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/cPanel/TaskQueue/PluginManager.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ sub load_plugin_by_name {
4848
my ($modname) = @_;
4949

5050
# Don't try to reload.
51-
return if exists $plugins_list{$modname};
51+
return 1 if exists $plugins_list{$modname};
5252

5353
eval "require $modname;"; ## no critic (ProhibitStringyEval)
5454
if ($@) {

t/taskqueue_plugin_manager_load_named.t

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ is_deeply( cPanel::TaskQueue::PluginManager::get_plugins_hash(), {}, 'No plugins
2626
is_deeply( $plugins, $expected, 'One module: Plugins and commands match' );
2727
}
2828

29-
plugin_load_no_ok( 'cPanel::FakeTasks::B', 'Cannot reload plugin' );
29+
plugin_load_ok( 'cPanel::FakeTasks::B', 'Cannot reload plugin' );
3030

3131
{
3232
ok( cPanel::TaskQueue::PluginManager::load_plugin_by_name('cPanel::FakeTasks::A'), 'Loaded second actual plugin' );
@@ -52,3 +52,17 @@ sub plugin_load_no_ok {
5252

5353
ok( !$status, $name );
5454
}
55+
56+
sub plugin_load_ok {
57+
my ($module, $name) = @_;
58+
59+
# Capture STDERR so Logger doesn't go to screen.
60+
open( my $olderr, '>&STDERR' ) or die "Can't dupe STDERR: $!";
61+
close( STDERR ); open( STDERR, '>', '/dev/null' ) or die "Unable to redirect STDERR: $!";
62+
63+
my $status = cPanel::TaskQueue::PluginManager::load_plugin_by_name( $module );
64+
65+
open( STDERR, '>&', $olderr ) or die "Unable to restore STDERR: $!";
66+
67+
ok( $status, $name );
68+
}

0 commit comments

Comments
 (0)