Drizzletest Commands

The commands that are endorsed in Drizzletest are delineated in the following documentation. Examples are given for the commands. Browse tests/t for more examples.

Note

The commands are not case sensitive. All commands must end with semi-colon.

List of commands

append_file

Syntax:

append_file file_name [terminator]

append_file command is used to append / add data to the end of an existing file. It is similar to write_file. In case, the specified file does not exist, it is created and the data is written on it. The end of data, that is to be appended, is marked by the terminator.

Note

The default terminator is EOF

The file_name can be substituted via variables.

Example:

let $MY_FILE = ~/foo/bar.txt;

append_file $MY_FILE;
writing text...
EOF

append_file $MY_FILE;
appending text with default terminator...
EOF

append_file $MY_FILE stop
appending text with `stop` terminator...
stop
Output:

~/foo/bar.txt:
writing text...
appending text with default terminator...
appending text with `stop` terminator...

cat_file

Syntax:

cat_file file_name

cat_file is similar to the unix cat command. cat_file expects only one argument. The cat_file command reads the file given as its argument and writes its contents to the test_name.result file.

Note

If extra argument is passed to cat_file command, the following error is displayed. testname: At line N: Extra argument ‘/path/to/file/file_name’ passed to ‘cat_file’

Example:

/foo/log.txt:
The test produced the following results:

/tests/t/test_name.test:
let $LOG_RESULT = /foo;
cat_file $LOG_RESULT/log.txt
SELECT 1;
Output:

/tests/r/test_name.result:
The test produced the following results:
SELECT 1;
1
1

Note

The file_name can be specified via variables. In the example above, we have used LOG_RESULT as variable. We can also specify it as “let $LOG_RESULT = /foo/log.txt” and use it as “cat_file $LOG_RESULT”.

change_user

Syntax:

change_user [user_name], [password], [db_name]

Example:


character_set

Syntax:

character_set charset_name

Example:


chmod

Syntax:

chmod octal_mode file_name

Example:


connect

Syntax:

connect (name, host_name, user_name, password, db_name [,port_num [,socket [,options [,default_auth]]]])

Example:


connection

Syntax:

connection connection_name

Example:


copy_file

Syntax:

copy_file from_file to_file

Example:


dec

Syntax:

dec $variable_name

dec takes in exactly one argument. The argument should be a variable. The dec decrements the value of the variable by 1. This command takes two forms. dec $variable_name; and - -dec $variable_name. This command is the reverse of inc

Note

If a constant is given as argument, the following error is thrown. ERROR:The argument to dec must be a variable (start with $)

Note

If two arguments are given, the following error is thrown ERROR:End of line junk detected

Example:

/tests/t/testname.test:
let $foo = 5;
echo $foo;
dec $foo;
echo $foo;
Output:

/tests/r/testname.result:
5
4

Note

If a string is stored in the variable, then it is not considered as an error. Decrementing such a variable will store -1 in the variable.

Example:

/tests/t/testname.test:
let $foo = 5;
echo $foo;
--dec $foo
echo $foo;
Output:

/tests/r/testname.result:
5
4

Note

In the second form, the ; is not required as a delimiter.

delimiter

Syntax:

delimiter string

delimiter is used to change the default delimiter ; to the one specified by the argument string. The default delimiter is ; (semi-colon). This command takes two forms. delimiter string and - -delimiter string.

Note

The string argument can have space in between. In such cases, the entire string (with the space) should be used as delimiter

Example:

/tests/t/testname.test:
SELECT 1;
delimiter stop;
SELECT 1 stop
Output:

/tests/r/testname.result:
SELECT 1;
1
1
SELECT 1 stop
1
1

Note

The strings are case sensitive. For example, if the delimiter is set to stop, then Stop or STOP cannot be considered as delimiter.

Example:

tests/t/testname.test:
SELECT 1;
--delimiter END OF LINE
SELECT 1 END OF LINE
Output:

tests/r/testname.result:
SELECT 1;
1
1
SELECT 1 END OF LINE
1
1

Note

In the above example, note the usage of --delimiter form. Also note the string with spaces in them.

When a string is set as delimiter, make sure that, the string is not used anywhere else. It should be unique. A common mistake that can be left unnoticed is given in the following example.

Example:

tests/t/testname.test:
CREATE TABLE test (id INT, start FLOAT, end FLOAT);
INSERT INTO test VALUES (1,10,12);
delimiter end;
SELECT start,end FROM test;

Note

We get the following error. At line 4: query ‘select start,’ failed: 1064: You have an error in your SQL syntax;

This test seems to be correct. However not that, the end in line 4 is treated as delimiter, and not as a field.

Note

To set the delimiter again to another one, delimiter new_delimiter should be followed by the old_delimiter

die

Syntax:

die [message]

die is used to terminate the test. This command takes in a message ( string ) as argument. When this line is executed, the test fails, and the message is printed as the reason for aborting the test. This is similar to exit.

Example:

tests/t/testname.test:
let $i=3;
while($i)
{
   die INFINITE LOOP ENCONTERED;
}
Output:

================================================================================
DEFAULT STORAGE ENGINE: innodb
TEST                                                         RESULT    TIME (ms)
--------------------------------------------------------------------------------

main.testname                                               [ fail ]
testname: At line 4: INFINITE LOOP ENCOUNTERED

Note

This is often used within a conditional statement such as if. That is, if a particular condition is reached, and the test will here after produce a fail result, then there is no need to carry out the remaining tests. Hence a die statement with the appropriate message can be used.

diff_files

Syntax:

diff_files file_name1 file_name2

Example:


dirty_close

Syntax:

dirty_close connection_name

disable/enable_abort_on_error

Syntax:

disable_abort_on_error,enable_abort_on_error

Example:


disable/enable_connect_log

Syntax:

disable_connect_log, enable_connect_log

Example:


disable/enable_info

Syntax:

disable_info, enable_info

Example:


disable/enable_metadata

Syntax:

disable_metadata, enable_metadata

Example:


disable/enable_parsing

Syntax:

disable_parsing, enable_parsing

Example:


disable/enable_ps_protocol

Syntax:

disable_ps_protocol, enable_ps_protocol

Example:


disable/enable_query_log

Syntax:

disable_query_log, enable_query_log

Example:


disable/enable_reconnect

Syntax:

disable_reconnect, enable_reconnect

Example:


disable/enable_result_log

Syntax:

disable_result_log, enable_result_log

Example:


disable/enable_rpl_parse

Syntax:

disable_rpl_parse, enable_rpl_parse

Example:


disable/enable_warnings

Syntax:

disable_warnings, enable_warnings

Example:


disconnect

Syntax:

disconnect connection_name

Example:


echo

Syntax:

echo text

echo is used to display text in the test.result file. This is often used for giving a verbose explanation about the test in the test.result file.

Note

If no text is provided, then a blank line is printed in the test.result file.

A good test file should echo all the important comments, so that, they are displayed into the test.result file for more clarity to the readers

Example:

tests/t/testname.test:
echo testing select statement...
--echo #test1
SELECT 1;
--echo #test2
SELECT 2;
Output:

test started...
#test1
SELECT 1;
1
1
#test2
SELECT 2;
2
2

In the above example, we can see that, comments test1 and test2 are echoed into the testname.result file. This gives a better understanding and clarity for the readers while tracing through the testname.result file.

end

Syntax:

end

end_timer

Syntax:

end_timer

error

Syntax:

error error_code [,error_code[,...]]

Example:


eval

Syntax:

eval statement

Example:


exec

Syntax:

exec command [arg1[,arg2[,...]]]

Example:


exit

Syntax:

exit

exit command is used to terminate the test. It is similar to die. However, here the test is not considered to have failed.

Example:

tests/t/testname.test:
SELECT 1;
exit
SELECT 2;
Output:

tests/r/testname.result:
SELECT 1;
1
1

Note

In the above example, the test for select 2 is not executed. Often this statement is used with a conditional statement such as if. That is, if a particular condition is satisfied, and the test has not yet failed so far, and needs no more testing, this exit statement can be used.

file_exists

Syntax:

file_exists file_name

Example:


horizontal_results

Syntax:

horizontal_results

Example:


if

Syntax:

if(expr)

Example:


inc

Syntax:

inc $var_name

inc takes in exactly one argument. The argument should be a variable. The inc increments the value of the variable by 1. This command takes two forms. inc $variable_name; and - -inc $variable_name. This command is the reverse of dec

Note

If a constant is given as argument, the following error is thrown. ERROR:The argument to inc must be a variable (start with $)

Note

If two arguments are given, the following error is thrown ERROR:End of line junk detected

Example:

/tests/t/testname.test:
let $foo = 5;
echo $foo;
inc $foo;
echo $foo;
Output:

/tests/r/testname.result:
5
6

Note

If a string is stored in the variable, then it is not considered as an error. Incrementing such a variable will store 1 in the variable.

Example:

/tests/t/testname.test:
let $foo = 5;
echo $foo;
--inc $foo
echo $foo;
Output:

/tests/r/testname.result:
5
6

Note

In the second form, the ; is not required as a delimiter.

let

Syntax:

let $var_name = value

let $var_name = query_get_value(query, col_name, row_num)

Example:


mkdir

Syntax:

mkdir dir_name

Example:


list_files

Syntax:

list_files dir_name [pattern]

Example:


list_files_append_file

Syntax:

list_files_append_file file_name dir_name [pattern]

Example:


list_files_write_file

Syntax:

list_files_write_file file_name dir_name [pattern]

Example:


lowercase_result

Syntax:

lowercase_result

Example:


move_file

Syntax:

move_file from_file to_file

Example:


perl

Syntax:

perl [terminator]

Example:


ping

Syntax:

ping

query

Syntax:

query [statement]

query_get_value

Syntax:

query_get_value(query,col_name,row_num)

Example:


query_horizontal

Syntax:

query_horizontal statement

Example:


query_vertical

Syntax:

query_vertical statement

Example:


real_sleep

Syntax:

real_sleep num

Example:


reap

Syntax:

reap

remove_file

Syntax:

remove_file file_name

Example:


remove_files_wildcard

Syntax:

remove_files_wildcard dir_name [pattern]

Example:


replace_column

Syntax:

replace_column col_num value [col_num value [,...] ]

Example:


replace_regex

Syntax:

replace_regex /pattern/replacement/[i] ...

Example:


replace_result

Syntax:

replace_result from_val to_val [from_val to_val [...]]

Example:


require

Syntax:

require file_name

Example:


result

Syntax:

result file_name

rmdir

Syntax:

rmdir dir_name

Example:


save_master_pos

Syntax:

save_master_pos

send

Syntax:

send [statement]

Example:


send_eval

Syntax:

send_eval [statement]

Example:


send_quit

Syntax:

send_quit [timeout]

Example:


shutdown_server

Syntax:

shutdown_server [timeout]

Example:


skip

Syntax:

skip [message]

Example:


sleep

Syntax:

sleep num

Example:


sorted_result

Syntax:

sorted_result

Example:


source

Syntax:

source file_name

Example:


start_timer

Syntax:

start_timer

sync_slave_with_master

Syntax:

sync_slave_with_master [connection_name]

sync_with_master

Syntax:

sync_with_master offset

system

Syntax:

system command [arg1[,arg2[,...]]]

Example:


vertical_results

Syntax:

vertical_results

Example:


wait_for_slave_to_stop

Syntax:

wait_for_slave_to_stop

while

Syntax:

while(expr)

while() defines an action block which gets executed over a loop. The while command expects a value / variable (expr) which decides whether or not the next iteration has to be carried out. If the value is 0, it is considered as false and the loop terminates. The body of the while block, which contains the set of statements to be executed repeatedly, should be enclosed within curly braces { and }.

Note

Any non-zero value, positive / negative is treated as a true, and the loop gets executed. The expression expr does not support boolean expressions.

Example:

/tests/t/testname.test:
let $test=3;
let $iteration=1;
while($test)
{
  echo test iteration $iteration;
  SELECT 1;
  dec $test;
  inc $iteration;
}
Output:

/tests/r/testname.result:
test iteration 1
SELECT 1;
1
1
test iteration 2
SELECT 1;
1
1
test iteration 3
SELECT 1;
1
1

Note

Ensure that, the expr value becomes zero at some point of time. Else, the loop gets executed infinitely and the test gets stalled.

write_file

Syntax:

write_file file_name [terminator]

write_file command is write data to the file specified by file_name. When this command is issued, a file with the name as file_name is created and data is written to it. The end of the data, that is to be written, is marked by the terminator.

Note

If the file exists, it is not considered as error / the test will not fail. Instead, the contents of the file will be replaced by the data that is to be written.

The file_name can be substituted via variables.

Example:

let $MY_FILE = ~/foo/bar.txt

write_file $MY_FILE;
testing...
EOF
Output:

~/foo/bar.txt:
testing...
Example:

let $MY_FILE = ~/foo/bar.txt

write_file $MY_FILE stop;
testing with test-run...
stop
Output:

~/foo/bar.txt:
testing with test-run...

Note

In the above example, the contents present previously in bar.txt are overwritten