From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 0EA486E454; Wed, 9 Feb 2022 20:53:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0EA486E454 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1644429211; bh=zw9KLIB5onp8GZLHLJSnIWZbmc4352ux85CFp9qebjU=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=CxTpJK6KPPCTz4WGlKEvUJfmkMr5IpJPJkA+5fGhIrcL2PbR9rSwVIRQnTZ6Uoy+V CR6RPp2SOt0OBoMjJxxYH0o2YfdRbHCHWXCQSBdh7bT8/InNMKJumg/lHAmhK/3cFh Q7x2TSWziM5sfSRa9aUY4TN+wH8RZwWf3nEtvHeM= Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 0E40C6E454 for ; Wed, 9 Feb 2022 20:53:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0E40C6E454 Received: by smtp61.i.mail.ru with esmtpa (envelope-from ) id 1nHr9k-0006vY-47; Wed, 09 Feb 2022 20:53:28 +0300 Message-ID: <94ba13ed-dd1f-a908-c4da-ec64fd415e4f@tarantool.org> Date: Wed, 9 Feb 2022 20:53:27 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9B74B50284A7C1A0BDB3817FC5E3D06AFA2654822E574318B182A05F5380850401921B406914CCA9120461D00C8C339AA74AC13C6D894937922CF7C5ADCC868F4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE71EAE3A63419E5AEDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378629C75C8EFA8C148638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C786E0A5B9A7E9C025EEFE90655C749D117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4BE21AE983DBD7FFC1D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3A7DFDF579AB090EF2D242C3BD2E3F4C6C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637AD0424077D726551EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 0D63561A33F958A5E9AC283EEBE7A6FF0C31EAB35736E9E7F1D8CC0B84BC5AE0D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75BFC02AB3DF06BA5A410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349A401E2B4D763A4A5696B41B044C9EA244788506EF61AE62B2F0BC6E066F1A59D45DA22A3A406B791D7E09C32AA3244C231D1032913EE37F31C8B99BF44A5C45F94338140B71B8EE729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojptAT+HCMDqP5Ui66k8vnAQ== X-Mailru-Sender: 583F1D7ACE8F49BD508BD8DBBD09B14DF6327956ED8DA88D098C0986762331E43C5642EA9D5B86B080EE221D05932256AD9BA6614E257C8ED9E51C16F2486AFBE342CF4F05FB7E8CB0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH vshard 1/4] test: support luatest X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Oleg Babin via Tarantool-patches Reply-To: Oleg Babin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for your patch. Am I right that it's partially imported from tarantool https://github.com/tarantool/tarantool/tree/master/test/luatest_helpers ? LGTM. See 2 minor comments/questions below. On 09.02.2022 03:32, Vladislav Shpilevoy wrote: > Test-run's most recent guideline is to write new tests in luatest > instead of diff console tests when possible. Luatest isn't exactly > in a perfect condition now, but it has 2 important features which > would be very useful in vshard: > > - Easy cluster build. All can be done programmatically except a > few basic things - from config creation to all replicasets > start, router start, and buckets bootstrap. No need to hardcode > that into files like storage_1_a.lua, router_1.lua, etc. > > - Can opt-out certain tests depending on Tarantool version. For > instance, soon coming support for netbox's return_raw option > will need to run tests only for > 2.10.0-beta2. In diff tests it > is also possible but would be notably complicated to achieve. > > Needed for #312 > --- > All luatest_helpers/ except vtest.lua are blindly copied from Tarantool's main > repo. I didn't check their bugs, code style, etc. > > test-run | 2 +- > test/instances/router.lua | 15 ++ > test/instances/storage.lua | 21 +++ > test/luatest_helpers.lua | 72 ++++++++ > test/luatest_helpers/asserts.lua | 43 +++++ > test/luatest_helpers/cluster.lua | 132 ++++++++++++++ > test/luatest_helpers/server.lua | 266 ++++++++++++++++++++++++++++ > test/luatest_helpers/vtest.lua | 135 ++++++++++++++ > test/router-luatest/router_test.lua | 54 ++++++ > test/router-luatest/suite.ini | 5 + > 10 files changed, 744 insertions(+), 1 deletion(-) > create mode 100755 test/instances/router.lua > create mode 100755 test/instances/storage.lua > create mode 100644 test/luatest_helpers.lua > create mode 100644 test/luatest_helpers/asserts.lua > create mode 100644 test/luatest_helpers/cluster.lua > create mode 100644 test/luatest_helpers/server.lua > create mode 100644 test/luatest_helpers/vtest.lua > create mode 100644 test/router-luatest/router_test.lua > create mode 100644 test/router-luatest/suite.ini > > diff --git a/test-run b/test-run > index c345003..2604c46 160000 > --- a/test-run > +++ b/test-run > @@ -1 +1 @@ > -Subproject commit c34500365efe8316e79c7936a2f2d04644602936 > +Subproject commit 2604c46c7b6368dbde59489d5303ce3d1d430331 > diff --git a/test/instances/router.lua b/test/instances/router.lua > new file mode 100755 > index 0000000..ccec6c1 > --- /dev/null > +++ b/test/instances/router.lua > @@ -0,0 +1,15 @@ > +#!/usr/bin/env tarantool > +local helpers = require('test.luatest_helpers') > +-- Do not load entire vshard into the global namespace to catch errors when code > +-- relies on that. > +_G.vshard = { > + router = require('vshard.router'), > +} > +-- Somewhy shutdown hangs on new Tarantools even though the nodes do not seem to > +-- have any long requests running. > +box.ctl.set_on_shutdown_timeout(0.001) > + > +box.cfg(helpers.box_cfg()) > +box.schema.user.grant('guest', 'super', nil, nil, {if_not_exists = true}) > + > +_G.ready = true > diff --git a/test/instances/storage.lua b/test/instances/storage.lua > new file mode 100755 > index 0000000..2d679ba > --- /dev/null > +++ b/test/instances/storage.lua > @@ -0,0 +1,21 @@ > +#!/usr/bin/env tarantool > +local helpers = require('test.luatest_helpers') > +-- Do not load entire vshard into the global namespace to catch errors when code > +-- relies on that. > +_G.vshard = { > + storage = require('vshard.storage'), > +} > +-- Somewhy shutdown hangs on new Tarantools even though the nodes do not seem to > +-- have any long requests running. > +box.ctl.set_on_shutdown_timeout(0.001) > + > +box.cfg(helpers.box_cfg()) > +box.schema.user.grant('guest', 'super', nil, nil, {if_not_exists = true}) > + > +local function echo(...) > + return ... > +end > + > +_G.echo = echo > + > +_G.ready = true > diff --git a/test/luatest_helpers.lua b/test/luatest_helpers.lua > new file mode 100644 > index 0000000..283906c > --- /dev/null > +++ b/test/luatest_helpers.lua > @@ -0,0 +1,72 @@ > +local fun = require('fun') > +local json = require('json') > +local fio = require('fio') > +local log = require('log') > +local yaml = require('yaml') > +local fiber = require('fiber') > + > +local luatest_helpers = { > + SOCKET_DIR = fio.abspath(os.getenv('VARDIR') or 'test/var') > +} Is fio.abspath really needed here? AFAIK the max length of unix socket is 108 symbols. Relative paths give a more chances that we don't face any issues. > + > +luatest_helpers.Server = require('test.luatest_helpers.server') > + > +local function default_cfg() > + return { > + work_dir = os.getenv('TARANTOOL_WORKDIR'), > + listen = os.getenv('TARANTOOL_LISTEN'), > + log = ('%s/%s.log'):format(os.getenv('TARANTOOL_WORKDIR'), os.getenv('TARANTOOL_ALIAS')), > + } > +end > + > +local function env_cfg() > + local src = os.getenv('TARANTOOL_BOX_CFG') > + if src == nil then > + return {} > + end > + local res = json.decode(src) > + assert(type(res) == 'table') > + return res > +end > + > +-- Collect box.cfg table from values passed through > +-- luatest_helpers.Server({<...>}) and from the given argument. > +-- > +-- Use it from inside an instance script. > +function luatest_helpers.box_cfg(cfg) > + return fun.chain(default_cfg(), env_cfg(), cfg or {}):tomap() > +end > + > +function luatest_helpers.instance_uri(alias, instance_id) > + if instance_id == nil then > + instance_id = '' > + end > + instance_id = tostring(instance_id) > + return ('%s/%s%s.iproto'):format(luatest_helpers.SOCKET_DIR, alias, instance_id); > +end > + > +function luatest_helpers:get_vclock(server) > + return server:eval('return box.info.vclock') > +end > + > +function luatest_helpers:wait_vclock(server, to_vclock) > + while true do > + local vclock = self:get_vclock(server) > + local ok = true > + for server_id, to_lsn in pairs(to_vclock) do > + local lsn = vclock[server_id] > + if lsn == nil or lsn < to_lsn then > + ok = false > + break > + end > + end > + if ok then > + return > + end > + log.info("wait vclock: %s to %s", yaml.encode(vclock), > + yaml.encode(to_vclock)) > + fiber.sleep(0.001) > + end > +end > + > +return luatest_helpers > diff --git a/test/luatest_helpers/asserts.lua b/test/luatest_helpers/asserts.lua > new file mode 100644 > index 0000000..77385d8 > --- /dev/null > +++ b/test/luatest_helpers/asserts.lua > @@ -0,0 +1,43 @@ > +local t = require('luatest') > + > +local asserts = {} > + > +function asserts:new(object) > + self:inherit(object) > + object:initialize() > + return object > +end > + > +function asserts:inherit(object) > + object = object or {} > + setmetatable(object, self) > + self.__index = self > + return object > +end > + > +function asserts:assert_server_follow_upstream(server, id) > + local status = server:eval( > + ('return box.info.replication[%d].upstream.status'):format(id)) > + t.assert_equals(status, 'follow', > + ('%s: this server does not follow others.'):format(server.alias)) > +end > + > + > +function asserts:wait_fullmesh(servers, wait_time) > + wait_time = wait_time or 20 > + t.helpers.retrying({timeout = wait_time}, function() > + for _, server in pairs(servers) do > + for _, server2 in pairs(servers) do > + if server ~= server2 then > + local server_id = server:eval('return box.info.id') > + local server2_id = server2:eval('return box.info.id') > + if server_id ~= server2_id then > + self:assert_server_follow_upstream(server, server2_id) Indention looks broken here (8 spaces instead of 4). > + end > + end > + end > + end > + end) > +end > + > +return asserts > diff --git a/test/luatest_helpers/cluster.lua b/test/luatest_helpers/cluster.lua > new file mode 100644 > index 0000000..43e3479