From ee901160010733de40c42cf51520928b8835b9ec Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Fri, 20 Feb 2015 18:17:07 +0300 Subject: [PATCH] Extract xlog.test into an own test suite. Deal with the collateral damage. Extract xlog.test.py into an own test suite, in preparation for a split into many tests. xlog.test.py restarts the server all the time anyway, there is no point to keep all tests in the same file. Deal with collateral damange of this seemingly innocuous move: * fix an assertion failure in user.drop(), user_has_data(). The check was using a wrong index. * fix test-run.py to leave cores around in case of a server crash (in a friendly gesture to develoeprs, and joining the ranks of such extremely succefful applications as apport and systemd, it used to delete them) * update bootstrap.snap to provide format for _index space * make a bunch of tests safe to the order in which they are executed * use space name rather than space id for error messages more often, since space id is very volatile after introduction of max_id sequence for space ids. --- extra/schema_fill.lua | 8 ++++++++ src/box/alter.cc | 14 +++++++++----- src/box/bootstrap.snap | Bin 2632 -> 2758 bytes src/box/lua/schema.lua | 30 ++++++++++++++++++++++++------ test/box/access_misc.result | 6 ++++-- test/box/alter.result | 2 +- test/box/alter_limits.result | 28 ++++++++++------------------ test/box/alter_limits.test.lua | 11 +++++------ test/box/bad_record.xlog | Bin 22 -> 0 bytes test/box/bootstrap.result | 4 +++- test/box/empty.xlog | Bin test/box/errinj.result | 2 +- test/box/iproto.result | 3 +++ test/box/iproto.test.py | 1 + test/box/just_header.xlog | Bin 11 -> 0 bytes test/box/sql.result | 3 +++ test/box/sql.test.py | 1 + test/lib/test_suite.py | 6 ++++-- test/xlog/suite.ini | 9 +++++++++ test/xlog/xlog.lua | 11 +++++++++++ test/{box => xlog}/xlog.result | 0 test/{box => xlog}/xlog.test.py | 0 22 files changed, 97 insertions(+), 42 deletions(-) delete mode 100644 test/box/bad_record.xlog delete mode 100644 test/box/empty.xlog delete mode 100644 test/box/just_header.xlog create mode 100644 test/xlog/suite.ini create mode 100644 test/xlog/xlog.lua rename test/{box => xlog}/xlog.result (100%) rename test/{box => xlog}/xlog.test.py (100%) diff --git a/extra/schema_fill.lua b/extra/schema_fill.lua index 3e41421338..b0010d443a 100644 --- a/extra/schema_fill.lua +++ b/extra/schema_fill.lua @@ -64,6 +64,14 @@ format[5] = {name='field_count', type='num'} format[6] = {name='flags', type='str'} format[7] = {name='format', type='*'} _space:format(format) +format = {} +format[1] = {name = 'id', type = 'num'} +format[2] = {name = 'iid', type = 'num'} +format[3] = {name = 'name', type = 'str'} +format[4] = {name = 'type', type = 'str'} +format[5] = {name = 'unique', type = 'num'} +format[6] = {name = 'part_count', type = 'num'} +_index:format(format) format={} format[1] = {name='id', type='num'} format[2] = {name='owner', type='num'} diff --git a/src/box/alter.cc b/src/box/alter.cc index 873626e86f..49f315dde7 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -1133,7 +1133,6 @@ space_has_data(uint32_t id, uint32_t iid, uint32_t uid) Index *index = space_index(space, iid); if (index == NULL) return false; - assert(strcmp(index->key_def->name, "owner") == 0); struct iterator *it = index->position(); char key[6]; assert(mp_sizeof_uint(SC_SYSTEM_ID_MIN) <= sizeof(key)); @@ -1149,10 +1148,15 @@ bool user_has_data(struct user *user) { uint32_t uid = user->uid; - uint32_t spaces[] = { SC_SPACE_ID, SC_FUNC_ID, SC_PRIV_ID }; - uint32_t *end = spaces + sizeof(spaces)/sizeof(*spaces); - for (uint32_t *i = spaces; i < end; i++) { - if (space_has_data(*i, 1, uid)) + uint32_t spaces[] = { SC_SPACE_ID, SC_FUNC_ID, SC_PRIV_ID, SC_PRIV_ID }; + /* + * owner index id #1 for _space and _func and _priv. + * For _priv also check that the user has no grants. + */ + uint32_t indexes[] = { 1, 1, 1, 0 }; + uint32_t count = sizeof(spaces)/sizeof(*spaces); + for (int i = 0; i < count; i++) { + if (space_has_data(spaces[i], indexes[i], uid)) return true; } if (! user_map_is_empty(&user->users)) diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap index 2b9f7089ecc76f00620f4a524f89bf815a8cff1a..4a675b75cf2b9b7a557a10ff55e70206e5b5fcf2 100644 GIT binary patch delta 357 zcmX>ha!j;7*v~P5%RtZ2h$}d?s4TU}O2N!1(K6B0I9WHz(9lBHBqc3XH!0OLSvMs) z$->kuEy*A;*^Dd9IVV3k+e)F@&`QCemW%7^F7DMf4Cl5y|Ld?k00NpAn3x%x1kN!q zFbXJ6TArL!T3nJ^bW_FB(89pP)Ff3m)xa`MT-PMo&=6>qaiXq8s)eChYMPOurIE$P zX}OGsXXZ1U%lzN+c^Se$Hi&@|iqp?BDljgK&&*3ntyr3ynp;xAuwdHcH%t;Ni!(D* zCUY^HYb`6y%PcHST~bn6kh(apG`DF<USe+Qs)EF#lKABO(!3J5%w}UI5mpwvMeF(} od$X%EGHfnppTOigYr!Xz<w$m`LF{%=oWyujg_uyfDzNq~0NamvFaQ7m delta 302 zcmX>mdP1Z=*v~P5%RtZ2h$}d?s4TU}O2NP~#oWX+)l@enG1)}d#3<21H_0?HN!KLN z*woC(z}(CrIgu;OIVV3k+e)F@5U8P+i|gtx?$tI7=WPF0X)h0efF=eeX2vFga|{fO z0*aHCC+CzFm!uZmR57uzv`8~Bx71BBH8U62H8D3$1zKQXtea|XYL;r2YG9mZkhpPL zE~9}W!@0TNKiDr{hA@x~VxWZLw6lx~jLYIP^HNePmgc7BmQ*k-*u0TRgq4MD^Figw pC)w2}SF>_%{>k3K<SN+Kbqm=LHHaY&ijx>`su1Jds{(7^0sv<bU8Vp4 diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 410379e8b5..e3d5f94871 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -272,7 +272,7 @@ end box.schema.create_space = box.schema.space.create -box.schema.space.drop = function(space_id) +box.schema.space.drop = function(space_id, space_name) check_param(space_id, 'space_id', 'number') local _space = box.space[box.schema.SPACE_ID] @@ -288,7 +288,10 @@ box.schema.space.drop = function(space_id) box.schema.user.revoke(tuple[2], tuple[5], tuple[3], tuple[4]) end if _space:delete{space_id} == nil then - box.error(box.error.NO_SUCH_SPACE, '#'..tostring(space_id)) + if space_name == nil then + space_name = '#'..tostring(space_id) + end + box.error(box.error.NO_SUCH_SPACE, space_name) end end @@ -561,6 +564,19 @@ builtin.port_ffi_create(port) ffi.gc(port, builtin.port_ffi_destroy) local port_t = ffi.typeof('struct port *') +-- Helper function for nicer error messages +-- in some cases when space object is misused +-- Takes time so should not be used for DML. +local function space_object_check(space) + if type(space) ~= 'table' then + space = { name = space } + end + local s = box.space[space.id] + if s == nil then + box.error(box.error.NO_SUCH_SPACE, space.name) + end +end + function box.schema.space.bless(space) local index_mt = {} -- __len and __index @@ -865,20 +881,22 @@ function box.schema.space.bless(space) return box.schema.space.format(space.id, format) end space_mt.drop = function(space) - return box.schema.space.drop(space.id) + return box.schema.space.drop(space.id, space.name) end space_mt.rename = function(space, name) + space_object_check(space) return box.schema.space.rename(space.id, name) end space_mt.create_index = function(space, name, options) + space_object_check(space) return box.schema.index.create(space.id, name, options) end space_mt.run_triggers = function(space, yesno) - local space = ffi.C.space_by_id(space.id) - if space == nil then + local s = ffi.C.space_by_id(space.id) + if s == nil then box.error(box.error.NO_SUCH_SPACE, space.name) end - ffi.C.space_run_triggers(space, yesno) + ffi.C.space_run_triggers(s, yesno) end space_mt.__index = space_mt diff --git a/test/box/access_misc.result b/test/box/access_misc.result index 377b136aec..8419c198ef 100644 --- a/test/box/access_misc.result +++ b/test/box/access_misc.result @@ -19,7 +19,7 @@ s:drop() ... s:drop() --- -- error: Space '#518' does not exist +- error: Space 'test' does not exist ... -- -- Check double create user @@ -585,7 +585,9 @@ box.space._space:select() 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'engine', 'type': 'str'}, {'name': 'field_count', 'type': 'num'}, {'name': 'flags', 'type': 'str'}, { 'name': 'format', 'type': '*'}]] - - [288, 1, '_index', 'memtx', 0, ''] + - [288, 1, '_index', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'iid', + 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'type', 'type': 'str'}, + {'name': 'unique', 'type': 'num'}, {'name': 'part_count', 'type': 'num'}]] - [296, 1, '_func', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'setuid', 'type': 'num'}]] - [304, 1, '_user', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', diff --git a/test/box/alter.result b/test/box/alter.result index 1cac72b604..97c3dd0e26 100644 --- a/test/box/alter.result +++ b/test/box/alter.result @@ -167,7 +167,7 @@ _index:select{} - [304, 1, 'owner', 'tree', 0, 1, 1, 'num'] - [304, 2, 'name', 'tree', 1, 1, 2, 'str'] - [312, 0, 'primary', 'tree', 1, 3, 1, 'num', 2, 'str', 3, 'num'] - - [312, 1, 'owner', 'tree', 0, 1, 1, 'num'] + - [312, 1, 'owner', 'tree', 0, 1, 0, 'num'] - [312, 2, 'object', 'tree', 0, 2, 2, 'str', 3, 'num'] - [320, 0, 'primary', 'tree', 1, 1, 0, 'num'] - [320, 1, 'uuid', 'tree', 1, 1, 1, 'str'] diff --git a/test/box/alter_limits.result b/test/box/alter_limits.result index a3defca9b8..3736290ea5 100644 --- a/test/box/alter_limits.result +++ b/test/box/alter_limits.result @@ -66,7 +66,7 @@ s:drop() -- no such space s:drop() --- -- error: Space '#738' does not exist +- error: Space 'tweedledum' does not exist ... -- no such engine box.schema.create_space('tweedleedee', { engine = 'unknown' }) @@ -276,9 +276,8 @@ box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 1}}) space' ... -- remove field_count - ok -box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 0}}) +_ = box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 0}}) --- -- [746, 1, 'test', 'memtx', 0, '', []] ... s:select{} --- @@ -298,9 +297,8 @@ s:select{} - [] ... -- set field_count of an empty space -box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) +_ = box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) --- -- [746, 1, 'test', 'memtx', 3, '', []] ... s:select{} --- @@ -648,19 +646,14 @@ s.index.primary:alter({type='tree', unique=false, name='pk'}) - error: 'Can''t create or modify index ''pk'' in space ''test'': primary key must be unique' ... ---# push filter 'function: .*' to 'function <pointer>' -s.index.primary +s.index.primary.name +--- +- primary +... +s.index.primary.id --- -- unique: true - parts: - - type: NUM - fieldno: 1 - id: 0 - space_id: 751 - name: primary - type: HASH +- 0 ... ---# clear filter s.index.pk.type --- - error: '[string "return s.index.pk.type "]:1: attempt to index field ''pk'' (a nil @@ -786,9 +779,8 @@ s.index.primary:select{} - ['Homevideo', 2011] - ['No such movie', 999] ... -box.space['_index']:update({s.id, s.index.year.id}, {{"=", 8, 'num'}}) +_ = box.space['_index']:update({s.id, s.index.year.id}, {{"=", 8, 'num'}}) --- -- [752, 1, 'year', 'tree', 0, 1, 1, 'num'] ... -- ambiguous field type index = s:create_index('str', { type = 'tree', unique = false, parts = { 2, 'str'}}) diff --git a/test/box/alter_limits.test.lua b/test/box/alter_limits.test.lua index bc1e9fafb4..065c4bfd31 100644 --- a/test/box/alter_limits.test.lua +++ b/test/box/alter_limits.test.lua @@ -96,14 +96,14 @@ s:select{} -- decrease field_count - error box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 1}}) -- remove field_count - ok -box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 0}}) +_ = box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 0}}) s:select{} -- increase field_count - error box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) s:truncate() s:select{} -- set field_count of an empty space -box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) +_ = box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) s:select{} -- field_count actually works s:insert{3, 4} @@ -233,9 +233,8 @@ s.index.primary.alter({unique=false}) s.index.primary:alter({unique=false}) -- unique -> non-unique, index type s.index.primary:alter({type='tree', unique=false, name='pk'}) ---# push filter 'function: .*' to 'function <pointer>' -s.index.primary ---# clear filter +s.index.primary.name +s.index.primary.id s.index.pk.type s.index.pk.unique s.index.pk:rename('primary') @@ -270,7 +269,7 @@ index = s:create_index('nodups', { type = 'tree', unique=true, parts = { 2, 'num -- change of non-unique index to unique: same effect s.index.year:alter({unique=true}) s.index.primary:select{} -box.space['_index']:update({s.id, s.index.year.id}, {{"=", 8, 'num'}}) +_ = box.space['_index']:update({s.id, s.index.year.id}, {{"=", 8, 'num'}}) -- ambiguous field type index = s:create_index('str', { type = 'tree', unique = false, parts = { 2, 'str'}}) -- create index on a non-existing field diff --git a/test/box/bad_record.xlog b/test/box/bad_record.xlog deleted file mode 100644 index 113b4df5648f8ca5dc22524ef8dc62deab3b378b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22 dcma#>@ptDk&@(jR;z~+PQ7B4H&M!*g0suaL1?m6* diff --git a/test/box/bootstrap.result b/test/box/bootstrap.result index 74f8dc32c3..f055177023 100644 --- a/test/box/bootstrap.result +++ b/test/box/bootstrap.result @@ -53,7 +53,9 @@ box.space._space:select{} 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'engine', 'type': 'str'}, {'name': 'field_count', 'type': 'num'}, {'name': 'flags', 'type': 'str'}, { 'name': 'format', 'type': '*'}]] - - [288, 1, '_index', 'memtx', 0, '', []] + - [288, 1, '_index', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'iid', + 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'type', 'type': 'str'}, + {'name': 'unique', 'type': 'num'}, {'name': 'part_count', 'type': 'num'}]] - [296, 1, '_func', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'setuid', 'type': 'num'}]] - [304, 1, '_user', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', diff --git a/test/box/empty.xlog b/test/box/empty.xlog deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/test/box/errinj.result b/test/box/errinj.result index e709a74502..fef2ad1c7a 100644 --- a/test/box/errinj.result +++ b/test/box/errinj.result @@ -271,7 +271,7 @@ box.space['withdata'] ... index7 = s_withdata:create_index('another', { type = 'tree', parts = { 5, 'num' }, unique = false}) --- -- error: Space '766' does not exist +- error: Space 'withdata' does not exist ... s_withdata.index.another --- diff --git a/test/box/iproto.result b/test/box/iproto.result index a9988eca43..32320bdfc8 100644 --- a/test/box/iproto.result +++ b/test/box/iproto.result @@ -150,3 +150,6 @@ STR 65536 space:drop() --- ... +box.schema.user.revoke('guest', 'read,write,execute', 'universe') +--- +... diff --git a/test/box/iproto.test.py b/test/box/iproto.test.py index 4c8d511bbd..688f1e0fbc 100644 --- a/test/box/iproto.test.py +++ b/test/box/iproto.test.py @@ -210,3 +210,4 @@ for test in TESTS: print admin("space:drop()") +admin("box.schema.user.revoke('guest', 'read,write,execute', 'universe')") diff --git a/test/box/just_header.xlog b/test/box/just_header.xlog deleted file mode 100644 index 82963618db683d5a6c344e50862eac8b8b21fe83..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11 Scma#>@ptDk&@(jR;sO8<jshA0 diff --git a/test/box/sql.result b/test/box/sql.result index 9bab5ad7f6..df4e0942d4 100644 --- a/test/box/sql.result +++ b/test/box/sql.result @@ -19,6 +19,9 @@ call f() index = box.space.test:create_index('primary', { type = 'hash' }) --- ... +box.schema.func.drop('f') +--- +... ping --- - ok diff --git a/test/box/sql.test.py b/test/box/sql.test.py index 2dfd8a6515..62ddcab93f 100644 --- a/test/box/sql.test.py +++ b/test/box/sql.test.py @@ -9,6 +9,7 @@ sql.authenticate('test', 'test') # call from sql to have the right owner sql("call f()") admin("index = box.space.test:create_index('primary', { type = 'hash' })") +admin("box.schema.func.drop('f')") sql("ping") # xxx: bug -- currently selects no rows sql("select * from t0") diff --git a/test/lib/test_suite.py b/test/lib/test_suite.py index 647379a830..faa73afb53 100644 --- a/test/lib/test_suite.py +++ b/test/lib/test_suite.py @@ -114,12 +114,14 @@ class TestSuite: failed_tests.append(test.name) color_stdout(shortsep, "\n", schema='separator') self.server.stop(silent=False) + # don't delete core files or state of the data dir + # in case of exception, which is raised when the + # server crashes + self.server.cleanup() except (KeyboardInterrupt) as e: color_stdout("\n%s\n" % shortsep, schema='separator') self.server.stop(silent=False) raise - finally: - self.server.cleanup() if failed_tests: color_stdout("Failed {0} tests: {1}.\n".format(len(failed_tests), diff --git a/test/xlog/suite.ini b/test/xlog/suite.ini new file mode 100644 index 0000000000..12ac02e030 --- /dev/null +++ b/test/xlog/suite.ini @@ -0,0 +1,9 @@ +[default] +core = tarantool +description = tarantool write ahead log tests +script = xlog.lua +disabled = +valgrind_disabled = +release_disabled = +lua_libs = +use_unix_sockets = True diff --git a/test/xlog/xlog.lua b/test/xlog/xlog.lua new file mode 100644 index 0000000000..ffe507f860 --- /dev/null +++ b/test/xlog/xlog.lua @@ -0,0 +1,11 @@ +#!/usr/bin/env tarantool +os = require('os') + +box.cfg{ + listen = os.getenv("LISTEN"), + slab_alloc_arena = 0.1, + pid_file = "tarantool.pid", + rows_per_wal = 50 +} + +require('console').listen(os.getenv('ADMIN')) diff --git a/test/box/xlog.result b/test/xlog/xlog.result similarity index 100% rename from test/box/xlog.result rename to test/xlog/xlog.result diff --git a/test/box/xlog.test.py b/test/xlog/xlog.test.py similarity index 100% rename from test/box/xlog.test.py rename to test/xlog/xlog.test.py -- GitLab