mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-15 16:00:23 +00:00
Removed ceiling argument passing, simply round up threshold now. Simplified test accordingly
This commit is contained in:
@@ -4802,7 +4802,6 @@ sub new {
|
|||||||
_check_and_set_vals(
|
_check_and_set_vals(
|
||||||
vars => $max_val_for,
|
vars => $max_val_for,
|
||||||
get_status => $args{get_status},
|
get_status => $args{get_status},
|
||||||
ceiling => $args{ceiling},
|
|
||||||
threshold_factor => 0.2, # +20%
|
threshold_factor => 0.2, # +20%
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -4953,7 +4952,7 @@ sub _check_and_set_vals {
|
|||||||
else {
|
else {
|
||||||
PTDEBUG && _d('Initial', $var, 'value:', $init_val);
|
PTDEBUG && _d('Initial', $var, 'value:', $init_val);
|
||||||
$val = ($init_val * $threshold_factor) + $init_val;
|
$val = ($init_val * $threshold_factor) + $init_val;
|
||||||
$vars->{$var} = $args{ceiling} ? int(ceil($val)) : int($val);
|
$vars->{$var} = int(ceil($val));
|
||||||
}
|
}
|
||||||
PTDEBUG && _d('Wait if', $var, '>=', $val);
|
PTDEBUG && _d('Wait if', $var, '>=', $val);
|
||||||
}
|
}
|
||||||
|
@@ -8347,6 +8347,7 @@ package MySQLStatusWaiter;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
|
use POSIX qw( ceil );
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||||
|
|
||||||
@@ -8512,8 +8513,8 @@ sub _check_and_set_vals {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PTDEBUG && _d('Initial', $var, 'value:', $init_val);
|
PTDEBUG && _d('Initial', $var, 'value:', $init_val);
|
||||||
$val = int(($init_val * $threshold_factor) + $init_val);
|
$val = ($init_val * $threshold_factor) + $init_val;
|
||||||
$vars->{$var} = $args{'ceiling'} ? ceil($val) : $val;
|
$vars->{$var} = int(ceil($val));
|
||||||
}
|
}
|
||||||
PTDEBUG && _d('Wait if', $var, '>=', $val);
|
PTDEBUG && _d('Wait if', $var, '>=', $val);
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,6 @@ sub new {
|
|||||||
_check_and_set_vals(
|
_check_and_set_vals(
|
||||||
vars => $max_val_for,
|
vars => $max_val_for,
|
||||||
get_status => $args{get_status},
|
get_status => $args{get_status},
|
||||||
ceiling => $args{ceiling},
|
|
||||||
threshold_factor => 0.2, # +20%
|
threshold_factor => 0.2, # +20%
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -224,7 +223,7 @@ sub _check_and_set_vals {
|
|||||||
else {
|
else {
|
||||||
PTDEBUG && _d('Initial', $var, 'value:', $init_val);
|
PTDEBUG && _d('Initial', $var, 'value:', $init_val);
|
||||||
$val = ($init_val * $threshold_factor) + $init_val;
|
$val = ($init_val * $threshold_factor) + $init_val;
|
||||||
$vars->{$var} = $args{ceiling} ? int(ceil($val)) : int($val);
|
$vars->{$var} = int(ceil($val));
|
||||||
}
|
}
|
||||||
PTDEBUG && _d('Wait if', $var, '>=', $val);
|
PTDEBUG && _d('Wait if', $var, '>=', $val);
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ use strict;
|
|||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use POSIX qw( ceil floor );
|
use POSIX qw( ceil floor );
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More tests => 22;
|
use Test::More tests => 17;
|
||||||
|
|
||||||
use MySQLStatusWaiter;
|
use MySQLStatusWaiter;
|
||||||
use PerconaTest;
|
use PerconaTest;
|
||||||
@@ -78,33 +78,35 @@ throws_ok(
|
|||||||
"Catch non-existent variable"
|
"Catch non-existent variable"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Use initial vals + 20%.
|
# Initial vals + 20%
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|
||||||
@vals = (
|
@vals = (
|
||||||
# initial check for existence
|
# initial check for existence
|
||||||
{ Threads_connected => 10, },
|
{ Threads_connected => 9, },
|
||||||
{ Threads_running => 5, },
|
{ Threads_running => 4, },
|
||||||
|
|
||||||
# first check, no wait
|
# first check, no wait
|
||||||
{ Threads_connected => 1, },
|
{ Threads_connected => 1, },
|
||||||
{ Threads_running => 1, },
|
{ Threads_running => 1, },
|
||||||
|
|
||||||
# second check, wait
|
# second check, wait
|
||||||
{ Threads_connected => 12, }, # too high
|
{ Threads_connected => 11, }, # too high
|
||||||
{ Threads_running => 6, }, # too high
|
{ Threads_running => 5, }, # too high
|
||||||
|
|
||||||
# third check, wait
|
# third check, wait
|
||||||
{ Threads_connected => 12, }, # too high
|
{ Threads_connected => 11, }, # too high
|
||||||
{ Threads_running => 5, },
|
{ Threads_running => 4, },
|
||||||
|
|
||||||
# fourth check, wait
|
# fourth check, wait
|
||||||
{ Threads_connected => 10, },
|
{ Threads_connected => 10, },
|
||||||
{ Threads_running => 6, }, # too high
|
{ Threads_running => 5, }, # too high
|
||||||
|
|
||||||
# fifth check, no wait
|
# fifth check, no wait
|
||||||
{ Threads_connected => 10, },
|
{ Threads_connected => 10, },
|
||||||
{ Threads_running => 5, },
|
{ Threads_running => 4, },
|
||||||
);
|
);
|
||||||
|
|
||||||
$oktorun = 1;
|
$oktorun = 1;
|
||||||
@@ -119,10 +121,10 @@ my $sw = new MySQLStatusWaiter(
|
|||||||
is_deeply(
|
is_deeply(
|
||||||
$sw->max_values(),
|
$sw->max_values(),
|
||||||
{
|
{
|
||||||
Threads_connected => int(10 + (10 * 0.20)),
|
Threads_connected => ceil(9 + (9 * 0.20)),
|
||||||
Threads_running => int(5 + (5 * 0.20)),
|
Threads_running => ceil(4 + (4 * 0.20)),
|
||||||
},
|
},
|
||||||
"Initial values +20%"
|
"Threshold = ceil(InitialValue * 1.2)"
|
||||||
);
|
);
|
||||||
|
|
||||||
# first check
|
# first check
|
||||||
@@ -164,94 +166,6 @@ is(
|
|||||||
"Slept until values low enough"
|
"Slept until values low enough"
|
||||||
);
|
);
|
||||||
|
|
||||||
# ############################################################################
|
|
||||||
# Initial vals + 20% plus ceiling option
|
|
||||||
# ############################################################################
|
|
||||||
|
|
||||||
@vals = (
|
|
||||||
# initial check for existence
|
|
||||||
{ Threads_connected => 9, },
|
|
||||||
{ Threads_running => 4, },
|
|
||||||
|
|
||||||
# first check, no wait
|
|
||||||
{ Threads_connected => 1, },
|
|
||||||
{ Threads_running => 1, },
|
|
||||||
|
|
||||||
# second check, wait
|
|
||||||
{ Threads_connected => 11, }, # too high
|
|
||||||
{ Threads_running => 5, }, # too high
|
|
||||||
|
|
||||||
# third check, wait
|
|
||||||
{ Threads_connected => 11, }, # too high
|
|
||||||
{ Threads_running => 4, },
|
|
||||||
|
|
||||||
# fourth check, wait
|
|
||||||
{ Threads_connected => 10, },
|
|
||||||
{ Threads_running => 5, }, # too high
|
|
||||||
|
|
||||||
# fifth check, no wait
|
|
||||||
{ Threads_connected => 10, },
|
|
||||||
{ Threads_running => 4, },
|
|
||||||
);
|
|
||||||
|
|
||||||
$oktorun = 1;
|
|
||||||
|
|
||||||
$sw = new MySQLStatusWaiter(
|
|
||||||
oktorun => \&oktorun,
|
|
||||||
get_status => \&get_status,
|
|
||||||
sleep => \&sleep,
|
|
||||||
ceiling => 'true',
|
|
||||||
max_spec => [qw(Threads_connected Threads_running)],
|
|
||||||
);
|
|
||||||
|
|
||||||
is_deeply(
|
|
||||||
$sw->max_values(),
|
|
||||||
{
|
|
||||||
Threads_connected => ceil(9 + (9 * 0.20)),
|
|
||||||
Threads_running => ceil(4 + (4 * 0.20)),
|
|
||||||
},
|
|
||||||
"Using Ceiling: Initial values = ceil(val+20%)"
|
|
||||||
);
|
|
||||||
|
|
||||||
# first check
|
|
||||||
@checked = ();
|
|
||||||
$slept = 0;
|
|
||||||
$sw->wait();
|
|
||||||
|
|
||||||
is_deeply(
|
|
||||||
\@checked,
|
|
||||||
[qw(Threads_connected Threads_running)],
|
|
||||||
"Using Ceiling: Checked both vars"
|
|
||||||
);
|
|
||||||
|
|
||||||
is(
|
|
||||||
$slept,
|
|
||||||
0,
|
|
||||||
"Using Ceiling: Vals not too high, did not sleep"
|
|
||||||
);
|
|
||||||
|
|
||||||
# second through fifth checks
|
|
||||||
@checked = ();
|
|
||||||
$slept = 0;
|
|
||||||
$sw->wait();
|
|
||||||
|
|
||||||
is_deeply(
|
|
||||||
\@checked,
|
|
||||||
[qw(
|
|
||||||
Threads_connected Threads_running
|
|
||||||
Threads_connected Threads_running
|
|
||||||
Threads_connected Threads_running
|
|
||||||
Threads_connected Threads_running
|
|
||||||
)],
|
|
||||||
"Using Ceiling: Rechecked all variables"
|
|
||||||
);
|
|
||||||
|
|
||||||
is(
|
|
||||||
$slept,
|
|
||||||
3,
|
|
||||||
"Using Ceiling: Slept until values low enough"
|
|
||||||
);
|
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Use static vals.
|
# Use static vals.
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
Reference in New Issue
Block a user