Skip to content

Commit

Permalink
Bug#29770237 REMOVE MYSQLTEST "REAL_SLEEP" COMMAND
Browse files Browse the repository at this point in the history
The mysqltest command "real_sleep" is an old artifact from early
days of MySQL development, it no longer serves any purpose.

  SELECT * FROM t1;
  --sleep 3
  SELECT * FROM T1

The intention was that one should be able write tests using the sleep
command and if the machine is slow, pass --sleep with a higher value
in order to increase the time slept during the test. This is not
practical in an automated test environment like we have today.

Using "mysqltest --sleep 1", the above sleep would be changed to 1
second and "mysqltest --sleep=10" would change it to 10 seconds.
If there are more sleep commands in a test, they will all be changed
to same value and hence, it doesn't scale.

We have already changed all usage of sleep into loops and there are
various include files to use to wait until certain condition has been
fulfilled. This has made it possible to run our test suite on both
slow and fast machines.

The patch does the following :-
- Removes the mysqltest "real_sleep" command. All instances of the
  command in the test suite are replaced with the "sleep" command.
- Removes the "mysqltest --sleep" command line argument.
- Removes the "mysql-test-run.pl --sleep" command line argument.
- Changes the mysqltest "sleep" command to always wait as long as
  argument specified.
- Updates the code comments for "do_sleep()" to indicate that
  fractional values can be used as a sleep value, not only whole
  seconds. i.e., sleep 0.1;
- Updates the mysqltest documentation to delete all information about
  the removed command and options. It also clearly describes that the
  "sleep" command supports sleeping for intervals which are less than
  one second.

Change-Id: I060d635aa3cbcb62323d1e5ea946264a44a56461
  • Loading branch information
Srikanth B R committed Mar 3, 2020
1 parent c164760 commit 686055c
Show file tree
Hide file tree
Showing 33 changed files with 130 additions and 209 deletions.
43 changes: 13 additions & 30 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ enum {
OPT_VIEW_PROTOCOL,
};

static int record = 0, opt_sleep = -1;
static int record = 0;
static char *opt_db = nullptr, *opt_pass = nullptr;
const char *opt_user = nullptr, *opt_host = nullptr, *unix_sock = nullptr,
*opt_basedir = "./";
Expand Down Expand Up @@ -429,7 +429,6 @@ enum enum_commands {
Q_QUERY,
Q_CONNECT,
Q_SLEEP,
Q_REAL_SLEEP,
Q_INC,
Q_DEC,
Q_SOURCE,
Expand Down Expand Up @@ -529,11 +528,10 @@ enum enum_commands {
};

const char *command_names[] = {
"connection", "query", "connect", "sleep", "real_sleep", "inc", "dec",
"source", "disconnect", "let", "echo", "expr", "while", "end",
"save_master_pos", "sync_with_master", "sync_slave_with_master", "error",
"send", "reap", "dirty_close", "replace_result", "replace_column", "ping",
"eval",
"connection", "query", "connect", "sleep", "inc", "dec", "source",
"disconnect", "let", "echo", "expr", "while", "end", "save_master_pos",
"sync_with_master", "sync_slave_with_master", "error", "send", "reap",
"dirty_close", "replace_result", "replace_column", "ping", "eval",
/* Enable/disable that the _query_ is logged to result file */
"enable_query_log", "disable_query_log",
/* Enable/disable that the _result_ from a query is logged to result file */
Expand Down Expand Up @@ -5209,23 +5207,17 @@ static void do_let(struct st_command *command) {
SYNOPSIS
do_sleep()
q called command
real_sleep use the value from opt_sleep as number of seconds to sleep
if real_sleep is false
DESCRIPTION
sleep <seconds>
real_sleep <seconds>
The difference between the sleep and real_sleep commands is that sleep
uses the delay from the --sleep command-line option if there is one.
(If the --sleep option is not given, the sleep command uses the delay
specified by its argument.) The real_sleep command always uses the
delay specified by its argument. The logic is that sometimes delays are
cpu-dependent, and --sleep can be used to set this delay. real_sleep is
used for cpu-independent delays.
Sleep <seconds>
The argument provided to --sleep command is not required to be
a whole number and can have fractional parts as well. For
example, '--sleep 0.1' is valid.
*/

static int do_sleep(struct st_command *command, bool real_sleep) {
static int do_sleep(struct st_command *command) {
int error = 0;
double sleep_val;
char *p;
Expand Down Expand Up @@ -5255,9 +5247,6 @@ static int do_sleep(struct st_command *command, bool real_sleep) {
command->first_argument);
dynstr_free(&ds_sleep);

/* Fixed sleep time selected by --sleep option */
if (opt_sleep >= 0 && !real_sleep) sleep_val = opt_sleep;

DBUG_PRINT("info", ("sleep_val: %f", sleep_val));
if (sleep_val) my_sleep((ulong)(sleep_val * 1000000L));
return 0;
Expand Down Expand Up @@ -7433,9 +7422,6 @@ static struct my_option my_long_options[] = {
0, nullptr},
{"silent", 's', "Suppress all normal output. Synonym for --quiet.", &silent,
&silent, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"sleep", 'T', "Always sleep this many seconds on sleep commands.",
&opt_sleep, &opt_sleep, nullptr, GET_INT, REQUIRED_ARG, -1, -1, 0, nullptr,
0, nullptr},
{"socket", 'S', "The socket file to use for connection.", &unix_sock,
&unix_sock, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
{"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select.",
Expand Down Expand Up @@ -9380,10 +9366,7 @@ int main(int argc, char **argv) {
do_source(command);
break;
case Q_SLEEP:
do_sleep(command, false);
break;
case Q_REAL_SLEEP:
do_sleep(command, true);
do_sleep(command);
break;
case Q_WAIT_FOR_SLAVE_TO_STOP:
do_wait_for_slave_to_stop(command);
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/extra/rpl_tests/rpl_row_001.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ connection master;
#
# Give slave time to do at last one failed connect retry
# This one must be short so that the slave will not stop retrying
real_sleep 2;
sleep 2;
SET PASSWORD FOR root@"localhost" = '';
# Give slave time to connect (will retry every second)
sleep 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let $wait_condition= SELECT count(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHE
--source include/wait_condition.inc

# Sleep on slave so we were at least 3 seconds behind the master
--real_sleep 3
--sleep 3
--source include/wait_for_mts_checkpoint.inc

let $sbm= query_get_value("SHOW SLAVE STATUS", Seconds_Behind_Master, 1);
Expand Down Expand Up @@ -148,7 +148,7 @@ let $wait_condition= SELECT count(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHE
--source include/wait_condition.inc

# Sleep for 2 seconds so Seconds_Behind_Master was at least 2
--real_sleep 2
--sleep 2

--source include/wait_for_mts_checkpoint.inc

Expand Down Expand Up @@ -244,7 +244,7 @@ let $wait_condition= SELECT count(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHE
--source include/wait_condition.inc

# Wait for 2 seconds so Second_Behind_Master is at least 2
--real_sleep 2
--sleep 2
--source include/wait_for_mts_checkpoint.inc

let $sbm= query_get_value("SHOW SLAVE STATUS", Seconds_Behind_Master, 1);
Expand All @@ -259,7 +259,7 @@ let $assert_cond= 2 <= $sbm AND $sbm <= $upper_bound;
connection slave3;
UNLOCK TABLES;

--real_sleep 1
--sleep 1

connection slave;
# Wait till worker on second_test db finishes
Expand Down Expand Up @@ -294,7 +294,7 @@ let $wait_condition= SELECT count(*) = 0 FROM INFORMATION_SCHEMA.PROCESSLIST WHE
OR State = 'update';
--source include/wait_condition.inc

--real_sleep 1
--sleep 1

--source include/wait_for_mts_checkpoint.inc

Expand All @@ -316,7 +316,7 @@ let $wait_condition= SELECT count(*) = 3 FROM INFORMATION_SCHEMA.PROCESSLIST WHE
# All catched up Seconds_Behind_Master should be 0. Lets wait some more to see if it does not increase
# Seconds_Behind_Master

--real_sleep 1
--sleep 1
--source include/wait_for_mts_checkpoint.inc

let $sbm= query_get_value("SHOW SLAVE STATUS", Seconds_Behind_Master, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ USE test;
let $start= `SELECT UNIX_TIMESTAMP()`;
INSERT INTO t1 VALUES (1);

--real_sleep 3
--sleep 3

USE test2;
let $start2= `SELECT UNIX_TIMESTAMP()`;
INSERT INTO t2 VALUES (1);
--real_sleep 2
--sleep 2

# Wait till all events are written to relay-log
--source include/sync_slave_io_with_master.inc
Expand Down Expand Up @@ -127,12 +127,12 @@ USE test;
let $start= `SELECT UNIX_TIMESTAMP()`;
INSERT INTO t1 VALUES (1);

--real_sleep 3
--sleep 3

USE test2;
let $start2= `SELECT UNIX_TIMESTAMP()`;
INSERT INTO t2 VALUES (1);
--real_sleep 2
--sleep 2

# Wait till all events are written to relay-log
--source include/sync_slave_io_with_master.inc
Expand Down Expand Up @@ -193,16 +193,16 @@ let $start= `SELECT UNIX_TIMESTAMP()`;

USE test;
INSERT INTO t1 VALUES (1);
--real_sleep 3
--sleep 3

use test2;
INSERT INTO t2 VALUES (1);
--real_sleep 2
--sleep 2

USE test3;
let $start3= `SELECT UNIX_TIMESTAMP()`;
INSERT INTO t3 VALUES (1);
--real_sleep 2
--sleep 2

--source include/sync_slave_io_with_master.inc

Expand Down
2 changes: 1 addition & 1 deletion mysql-test/extra/rpl_tests/rpl_semi_sync_deadlock.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ while ($i < $n)

--connection master1
SET DEBUG_SYNC= "before_rotate_binlog SIGNAL signal.continue";
--real_sleep 3
--sleep 3
--echo # Rotate binlog file
FLUSH LOGS;

Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/connect2.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ while ($wait_counter)
}
if ($error)
{
real_sleep 0.1;
sleep 0.1;
dec $wait_counter;
}
}
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/wait_condition.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ while ($wait_counter)
}
if (!$success)
{
real_sleep 0.1;
sleep 0.1;
dec $wait_counter;
}
}
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/wait_condition_sp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ while ($wait_counter)
}
if (!$success)
{
real_sleep 0.1;
sleep 0.1;
dec $wait_counter;
}
}
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/wait_condition_with_sql.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ while ($wait_counter)
}
if (!$success)
{
real_sleep 0.1;
sleep 0.1;
dec $retry_counter;
}
}
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/wait_for_binlog_event.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ while (`SELECT INSTR("$_last_event","$wait_binlog_event") = 0`)
--source include/show_rpl_debug_info.inc
--die ERROR: failed while waiting for $wait_binlog_event in binlog
}
real_sleep 0.1;
sleep 0.1;
let $_event= query_get_value($_show_events_query, Info, $_event_pos);
let $_last_event= $_event;
while ($_event != "No such row")
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/wait_innodb_all_purged.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ WHERE VARIABLE_NAME = 'INNODB_PURGE_VIEW_TRX_ID_AGE';`;
if (!$success)
{
set global innodb_purge_run_now=ON;
real_sleep 0.1;
sleep 0.1;
dec $wait_counter;
}
}
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/include/wait_show_condition.inc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if ($wait_for_all != 1)
while (`SELECT UNIX_TIMESTAMP() <= $max_end_time AND $found = 0`)
{
# Sleep a bit to avoid too heavy load.
real_sleep 0.2;
sleep 0.2;
let $rowno= 1;
let $process_result= 1;
let $do_loop= 1;
Expand Down Expand Up @@ -103,7 +103,7 @@ if ($wait_for_all == 1)
while (`SELECT UNIX_TIMESTAMP() <= $max_end_time AND $found = 0`)
{
# Sleep a bit to avoid too heavy load.
real_sleep 0.2;
sleep 0.2;
let $rowno= 1;
let $process_result= 1;
let $do_loop= 1;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/wait_until_count_sessions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ while ($wait_counter)
}
if (!$success)
{
real_sleep 0.1;
sleep 0.1;
dec $wait_counter;
}
}
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/wait_until_undo_space_is_empty.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ while ($wait_seconds)
}
if (!$success_wait)
{
real_sleep 0.1;
sleep 0.1;
}
dec $repeat;
}
Expand Down
Loading

0 comments on commit 686055c

Please sign in to comment.