From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 6296724E23 for ; Mon, 23 Jul 2018 07:14:37 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8cOvPRTWKEKz for ; Mon, 23 Jul 2018 07:14:37 -0400 (EDT) Received: from smtp36.i.mail.ru (smtp36.i.mail.ru [94.100.177.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id B54C4242C5 for ; Mon, 23 Jul 2018 07:14:36 -0400 (EDT) From: AKhatskevich Subject: [tarantool-patches] [PATCH 3/4] Tests: separate bootstrap routine to a lua_libs Date: Mon, 23 Jul 2018 14:14:21 +0300 Message-Id: <93c39ca3ca0a450afaf1e0aaf865933f1b99ffad.1532344376.git.avkhatskevich@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org What is moved to `test/lul_libs/bootstrap_test_storage.lua`: 1. create schema 2. create main stored procedures 3. `wait_rebalancer_state` procedure This code would be reused it further commits. --- test/lua_libs/bootstrap_test_storage.lua | 50 ++++++++++++++++++++++ test/rebalancer/box_1_a.lua | 47 ++------------------ test/rebalancer/errinj.result | 2 +- test/rebalancer/errinj.test.lua | 2 +- test/rebalancer/rebalancer.result | 2 +- test/rebalancer/rebalancer.test.lua | 2 +- test/rebalancer/rebalancer_lock_and_pin.result | 2 +- test/rebalancer/rebalancer_lock_and_pin.test.lua | 2 +- test/rebalancer/restart_during_rebalancing.result | 2 +- .../rebalancer/restart_during_rebalancing.test.lua | 2 +- test/rebalancer/stress_add_remove_rs.result | 2 +- test/rebalancer/stress_add_remove_rs.test.lua | 2 +- .../rebalancer/stress_add_remove_several_rs.result | 2 +- .../stress_add_remove_several_rs.test.lua | 2 +- test/rebalancer/suite.ini | 2 +- 15 files changed, 66 insertions(+), 57 deletions(-) create mode 100644 test/lua_libs/bootstrap_test_storage.lua diff --git a/test/lua_libs/bootstrap_test_storage.lua b/test/lua_libs/bootstrap_test_storage.lua new file mode 100644 index 0000000..62c2f78 --- /dev/null +++ b/test/lua_libs/bootstrap_test_storage.lua @@ -0,0 +1,50 @@ +local log = require('log') + +function init_schema() + local format = {} + format[1] = {name = 'field', type = 'unsigned'} + format[2] = {name = 'bucket_id', type = 'unsigned'} + local s = box.schema.create_space('test', {format = format}) + local pk = s:create_index('pk') + local bucket_id_idx = + s:create_index('vbucket', {parts = {'bucket_id'}, + unique = false}) +end + +box.once('schema', function() + box.schema.func.create('do_replace') + box.schema.role.grant('public', 'execute', 'function', 'do_replace') + box.schema.func.create('do_select') + box.schema.role.grant('public', 'execute', 'function', 'do_select') + init_schema() +end) + +function do_replace(...) + box.space.test:replace(...) + return true +end + +function do_select(...) + return box.space.test:select(...) +end + +function check_consistency() + for _, tuple in box.space.test:pairs() do + assert(box.space._bucket:get{tuple.bucket_id}) + end + return true +end + +-- +-- Wait a specified log message. +-- Requirements: +-- * Should be executed from a storage with a rebalancer. +-- * NAME - global variable, name of instance should be set. +function wait_rebalancer_state(state, test_run) + log.info(string.rep('a', 1000)) + vshard.storage.rebalancer_wakeup() + while not test_run:grep_log(NAME, state, 1000) do + fiber.sleep(0.1) + vshard.storage.rebalancer_wakeup() + end +end diff --git a/test/rebalancer/box_1_a.lua b/test/rebalancer/box_1_a.lua index 8fddcf0..8ab3444 100644 --- a/test/rebalancer/box_1_a.lua +++ b/test/rebalancer/box_1_a.lua @@ -2,7 +2,7 @@ -- Get instance name require('strict').on() local fio = require('fio') -local NAME = fio.basename(arg[0], '.lua') +NAME = fio.basename(arg[0], '.lua') log = require('log') require('console').listen(os.getenv('ADMIN')) fiber = require('fiber') @@ -23,40 +23,8 @@ if NAME == 'box_4_a' or NAME == 'box_4_b' or end vshard.storage.cfg(cfg, names.replica_uuid[NAME]) -function init_schema() - local format = {} - format[1] = {name = 'field', type = 'unsigned'} - format[2] = {name = 'bucket_id', type = 'unsigned'} - local s = box.schema.create_space('test', {format = format}) - local pk = s:create_index('pk') - local bucket_id_idx = - s:create_index('vbucket', {parts = {'bucket_id'}, - unique = false}) -end - -box.once('schema', function() - box.schema.func.create('do_replace') - box.schema.role.grant('public', 'execute', 'function', 'do_replace') - box.schema.func.create('do_select') - box.schema.role.grant('public', 'execute', 'function', 'do_select') - init_schema() -end) - -function do_replace(...) - box.space.test:replace(...) - return true -end - -function do_select(...) - return box.space.test:select(...) -end - -function check_consistency() - for _, tuple in box.space.test:pairs() do - assert(box.space._bucket:get{tuple.bucket_id}) - end - return true -end +-- Bootstrap storage. +require('lua_libs.bootstrap_test_storage') function switch_rs1_master() local replica_uuid = names.replica_uuid @@ -68,12 +36,3 @@ end function nullify_rs_weight() cfg.sharding[names.rs_uuid[1]].weight = 0 end - -function wait_rebalancer_state(state, test_run) - log.info(string.rep('a', 1000)) - vshard.storage.rebalancer_wakeup() - while not test_run:grep_log(NAME, state, 1000) do - fiber.sleep(0.1) - vshard.storage.rebalancer_wakeup() - end -end diff --git a/test/rebalancer/errinj.result b/test/rebalancer/errinj.result index d09349e..826c2c6 100644 --- a/test/rebalancer/errinj.result +++ b/test/rebalancer/errinj.result @@ -13,7 +13,7 @@ test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') --- ... -util = require('util') +util = require('lua_libs.util') --- ... util.wait_master(test_run, REPLICASET_1, 'box_1_a') diff --git a/test/rebalancer/errinj.test.lua b/test/rebalancer/errinj.test.lua index d6a2920..fc0730c 100644 --- a/test/rebalancer/errinj.test.lua +++ b/test/rebalancer/errinj.test.lua @@ -5,7 +5,7 @@ REPLICASET_2 = { 'box_2_a', 'box_2_b' } test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') -util = require('util') +util = require('lua_libs.util') util.wait_master(test_run, REPLICASET_1, 'box_1_a') util.wait_master(test_run, REPLICASET_2, 'box_2_a') diff --git a/test/rebalancer/rebalancer.result b/test/rebalancer/rebalancer.result index 88cbaae..71e43e1 100644 --- a/test/rebalancer/rebalancer.result +++ b/test/rebalancer/rebalancer.result @@ -13,7 +13,7 @@ test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') --- ... -util = require('util') +util = require('lua_libs.util') --- ... util.wait_master(test_run, REPLICASET_1, 'box_1_a') diff --git a/test/rebalancer/rebalancer.test.lua b/test/rebalancer/rebalancer.test.lua index 01f2061..1b7ddae 100644 --- a/test/rebalancer/rebalancer.test.lua +++ b/test/rebalancer/rebalancer.test.lua @@ -5,7 +5,7 @@ REPLICASET_2 = { 'box_2_a', 'box_2_b' } test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') -util = require('util') +util = require('lua_libs.util') util.wait_master(test_run, REPLICASET_1, 'box_1_a') util.wait_master(test_run, REPLICASET_2, 'box_2_a') diff --git a/test/rebalancer/rebalancer_lock_and_pin.result b/test/rebalancer/rebalancer_lock_and_pin.result index dd9fe47..0f2921c 100644 --- a/test/rebalancer/rebalancer_lock_and_pin.result +++ b/test/rebalancer/rebalancer_lock_and_pin.result @@ -16,7 +16,7 @@ test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') --- ... -util = require('util') +util = require('lua_libs.util') --- ... util.wait_master(test_run, REPLICASET_1, 'box_1_a') diff --git a/test/rebalancer/rebalancer_lock_and_pin.test.lua b/test/rebalancer/rebalancer_lock_and_pin.test.lua index fe866c4..3a2daa0 100644 --- a/test/rebalancer/rebalancer_lock_and_pin.test.lua +++ b/test/rebalancer/rebalancer_lock_and_pin.test.lua @@ -6,7 +6,7 @@ REPLICASET_3 = { 'box_3_a', 'box_3_b' } test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') -util = require('util') +util = require('lua_libs.util') util.wait_master(test_run, REPLICASET_1, 'box_1_a') util.wait_master(test_run, REPLICASET_2, 'box_2_a') diff --git a/test/rebalancer/restart_during_rebalancing.result b/test/rebalancer/restart_during_rebalancing.result index d2b8a12..0eb0f2e 100644 --- a/test/rebalancer/restart_during_rebalancing.result +++ b/test/rebalancer/restart_during_rebalancing.result @@ -25,7 +25,7 @@ test_run:create_cluster(REPLICASET_3, 'rebalancer') test_run:create_cluster(REPLICASET_4, 'rebalancer') --- ... -util = require('util') +util = require('lua_libs.util') --- ... util.wait_master(test_run, REPLICASET_1, 'fullbox_1_a') diff --git a/test/rebalancer/restart_during_rebalancing.test.lua b/test/rebalancer/restart_during_rebalancing.test.lua index 5b1a8df..7b707ca 100644 --- a/test/rebalancer/restart_during_rebalancing.test.lua +++ b/test/rebalancer/restart_during_rebalancing.test.lua @@ -9,7 +9,7 @@ test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') test_run:create_cluster(REPLICASET_3, 'rebalancer') test_run:create_cluster(REPLICASET_4, 'rebalancer') -util = require('util') +util = require('lua_libs.util') util.wait_master(test_run, REPLICASET_1, 'fullbox_1_a') util.wait_master(test_run, REPLICASET_2, 'fullbox_2_a') util.wait_master(test_run, REPLICASET_3, 'fullbox_3_a') diff --git a/test/rebalancer/stress_add_remove_rs.result b/test/rebalancer/stress_add_remove_rs.result index 8a955e2..10bcaac 100644 --- a/test/rebalancer/stress_add_remove_rs.result +++ b/test/rebalancer/stress_add_remove_rs.result @@ -16,7 +16,7 @@ test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') --- ... -util = require('util') +util = require('lua_libs.util') --- ... util.wait_master(test_run, REPLICASET_1, 'box_1_a') diff --git a/test/rebalancer/stress_add_remove_rs.test.lua b/test/rebalancer/stress_add_remove_rs.test.lua index c80df40..b9bb027 100644 --- a/test/rebalancer/stress_add_remove_rs.test.lua +++ b/test/rebalancer/stress_add_remove_rs.test.lua @@ -6,7 +6,7 @@ REPLICASET_3 = { 'box_3_a', 'box_3_b' } test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') -util = require('util') +util = require('lua_libs.util') util.wait_master(test_run, REPLICASET_1, 'box_1_a') util.wait_master(test_run, REPLICASET_2, 'box_2_a') diff --git a/test/rebalancer/stress_add_remove_several_rs.result b/test/rebalancer/stress_add_remove_several_rs.result index d6008b8..611362c 100644 --- a/test/rebalancer/stress_add_remove_several_rs.result +++ b/test/rebalancer/stress_add_remove_several_rs.result @@ -19,7 +19,7 @@ test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') --- ... -util = require('util') +util = require('lua_libs.util') --- ... util.wait_master(test_run, REPLICASET_1, 'box_1_a') diff --git a/test/rebalancer/stress_add_remove_several_rs.test.lua b/test/rebalancer/stress_add_remove_several_rs.test.lua index 3cc105e..9acb8de 100644 --- a/test/rebalancer/stress_add_remove_several_rs.test.lua +++ b/test/rebalancer/stress_add_remove_several_rs.test.lua @@ -7,7 +7,7 @@ REPLICASET_4 = { 'box_4_a', 'box_4_b' } test_run:create_cluster(REPLICASET_1, 'rebalancer') test_run:create_cluster(REPLICASET_2, 'rebalancer') -util = require('util') +util = require('lua_libs.util') util.wait_master(test_run, REPLICASET_1, 'box_1_a') util.wait_master(test_run, REPLICASET_2, 'box_2_a') diff --git a/test/rebalancer/suite.ini b/test/rebalancer/suite.ini index afc5141..8689da5 100644 --- a/test/rebalancer/suite.ini +++ b/test/rebalancer/suite.ini @@ -4,6 +4,6 @@ description = Rebalancer tests script = test.lua is_parallel = False release_disabled = errinj.test.lua -lua_libs = ../lua_libs/util.lua config.lua names.lua router_1.lua +lua_libs = ../lua_libs config.lua names.lua router_1.lua box_1_a.lua box_1_b.lua box_2_a.lua box_2_b.lua box_3_a.lua box_3_b.lua rebalancer_utils.lua -- 2.14.1