From e25e4d4864492c7e95fa8affd2e2da0a3864c896 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Thu, 5 Jan 2017 23:00:13 +0300 Subject: [PATCH] Lua API regression tests. --- tests/t/api_basic.t | 64 +++++++++++++++++++++++++++++++++++++++++++++ tests/t/api_rand.t | 26 ++++++++++++++++++ tests/t/api_sql.t | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 tests/t/api_basic.t create mode 100644 tests/t/api_rand.t create mode 100644 tests/t/api_sql.t diff --git a/tests/t/api_basic.t b/tests/t/api_basic.t new file mode 100644 index 0000000..8477a61 --- /dev/null +++ b/tests/t/api_basic.t @@ -0,0 +1,64 @@ +######################################################################## +Basic Lua API tests +######################################################################## + + $ if [ -z "${SBTEST_MYSQL_ARGS:-}" ] + > then + > exit 80 + > fi + + $ SB_ARGS="--verbosity=0 --test=$CRAMTMP/api_basic.lua --max-requests=2 --num-threads=1" + + $ cat >$CRAMTMP/api_basic.lua < function init(thread_id) + > print("tid:" .. (thread_id or "(nil)") .. " init()") + > end + > + > function prepare(thread_id) + > print("tid:" .. (thread_id or "(nil)") .. " prepare()") + > end + > + > function run(thread_id) + > print("tid:" .. (thread_id or "(nil)") .. " run()") + > end + > + > function cleanup(thread_id) + > print("tid:" .. (thread_id or "(nil)") .. " cleanup()") + > end + > + > function help() + > print("tid:" .. (thread_id or "(nil)") .. " help()") + > end + > + > function thread_init(thread_id) + > print(string.format("tid:%d thread_init()", thread_id)) + > end + > + > function event(thread_id) + > print(string.format("tid:%d event()", thread_id)) + > end + > + > function thread_done(thread_id) + > print(string.format("tid:%d thread_done()", thread_id)) + > end + > + > function done(thread_id) + > print("tid:" .. (thread_id or "(nil)") .. " done()") + > end + > + > EOF + + $ sysbench $SB_ARGS prepare + tid:(nil) prepare() + + $ sysbench $SB_ARGS run + tid:0 thread_init() + tid:0 event() + tid:0 event() + tid:0 thread_done() + + $ sysbench $SB_ARGS cleanup + tid:(nil) cleanup() + + $ sysbench $SB_ARGS help + tid:(nil) help() diff --git a/tests/t/api_rand.t b/tests/t/api_rand.t new file mode 100644 index 0000000..66d0e53 --- /dev/null +++ b/tests/t/api_rand.t @@ -0,0 +1,26 @@ +######################################################################## +PRNG Lua API tests +######################################################################## + + $ SB_ARGS="--verbosity=0 --test=$CRAMTMP/api_rand.lua --max-requests=1 --num-threads=1" + + $ cat >$CRAMTMP/api_rand.lua < function event() + > print("sb_rand(0, 9) = " .. sb_rand(0, 9)) + > print("sb_rand_uniq(0, 9) = " .. sb_rand_uniq(0, 9)) + > print("sb_rnd() = " .. sb_rnd()) + > print([[sb_rand_str("abc-###-@@@-xyz") = ]] .. sb_rand_str("abc-###-@@@-xyz")) + > print("sb_rand_uniform(0, 9) = " .. sb_rand_uniform(0, 9)) + > print("sb_rand_gaussian(0, 9) = " .. sb_rand_gaussian(0, 9)) + > print("sb_rand_special(0, 9) = " .. sb_rand_special(0, 9)) + > end + > EOF + + $ sysbench $SB_ARGS run + sb_rand\(0, 9\) = [0-9]{1} (re) + sb_rand_uniq\(0, 9\) = [0-9]{1} (re) + sb_rnd\(\) = [0-9]+ (re) + sb_rand_str\(".*"\) = abc-[0-9]{3}-[a-z]{3}-xyz (re) + sb_rand_uniform\(0, 9\) = [0-9]{1} (re) + sb_rand_gaussian\(0, 9\) = [0-9]{1} (re) + sb_rand_special\(0, 9\) = [0-9]{1} (re) diff --git a/tests/t/api_sql.t b/tests/t/api_sql.t new file mode 100644 index 0000000..e9e76c7 --- /dev/null +++ b/tests/t/api_sql.t @@ -0,0 +1,62 @@ +######################################################################## +SQL Lua API tests +######################################################################## + + $ if [ -z "${SBTEST_MYSQL_ARGS:-}" ] + > then + > exit 80 + > fi + + $ SB_ARGS="--verbosity=1 --test=$CRAMTMP/api_sql.lua --max-requests=1 --num-threads=1" + $ cat >$CRAMTMP/api_sql.lua < function event(thread_id) + > db_query("CREATE TABLE t(a INT)") + > + > db_bulk_insert_init("INSERT INTO t VALUES") + > for i = 1,100 do + > db_bulk_insert_next(string.format("(%d)", i)) + > end + > db_bulk_insert_done() + > + > db_connect() + > db_query("SELECT 1") + > db_disconnect() + > db_query("SELECT 1") + > db_connect() + > + > local stmt = db_prepare("UPDATE t SET a = a + ?") + > db_bind_param(stmt, {100}) + > rs = db_execute(stmt) + > db_store_results(rs) + > db_free_results(rs) + > db_close(stmt) + > + > print("DB_ERROR_NONE = " .. DB_ERROR_NONE) + > print("DB_ERROR_RESTART_TRANSACTION = " .. DB_ERROR_RESTART_TRANSACTION) + > print("DB_ERROR_FAILED = " .. DB_ERROR_FAILED) + > end + > EOF + + $ mysql -uroot sbtest -Nse "DROP TABLE IF EXISTS t" + + $ sysbench $SB_ARGS run + DB_ERROR_NONE = 0 + DB_ERROR_RESTART_TRANSACTION = 1 + DB_ERROR_FAILED = 3 + + $ mysql -uroot sbtest -Nse "SHOW CREATE TABLE t\G" + *************************** 1. row *************************** + t + CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL + ) ENGINE=InnoDB DEFAULT CHARSET=latin1 + + $ mysql -uroot sbtest -Nse "SELECT COUNT(DISTINCT a) FROM t" + 100 + + $ mysql -uroot sbtest -Nse "SELECT MIN(a), MAX(a) FROM t\G" + *************************** 1. row *************************** + 101 + 200 + + $ mysql -uroot sbtest -Nse "DROP TABLE t"