Lua API regression tests.
This commit is contained in:
64
tests/t/api_basic.t
Normal file
64
tests/t/api_basic.t
Normal file
@ -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 <<EOF
|
||||
> 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()
|
||||
26
tests/t/api_rand.t
Normal file
26
tests/t/api_rand.t
Normal file
@ -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 <<EOF
|
||||
> 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)
|
||||
62
tests/t/api_sql.t
Normal file
62
tests/t/api_sql.t
Normal file
@ -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 <<EOF
|
||||
> 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"
|
||||
Reference in New Issue
Block a user