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 468336F3E5; Mon, 8 Nov 2021 18:16:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 468336F3E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636384607; bh=aoXd9KWT+5VdHhRYynX5GL2Bow9kWvEdjZ7TswhrtAY=; 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=WhbgyvReZNjoy0ZU/vmh2Mu24Dv9E15YklIOZ3yLT+QEYajZKqaq3Z6t3y5ti9GHP l18Z8Tj6H4+YPcT/yhPe3U78kqjt4Zk4KJqD2VDIMG04YgyGMTt/gBOWGiPuKfVzRy GJmhfcHnsIvPaVQDYLLDngO+yXYZPI5bjdvUDBtw= Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [94.100.177.111]) (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 383636F3E5 for ; Mon, 8 Nov 2021 18:16:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 383636F3E5 Received: by smtp51.i.mail.ru with esmtpa (envelope-from ) id 1mk6O5-00050Z-7k; Mon, 08 Nov 2021 18:16:45 +0300 Message-ID: <03971784-b1d0-1366-f03b-2e10fce807f6@tarantool.org> Date: Mon, 8 Nov 2021 18:16:44 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org, vdavydov@tarantool.org References: <9a8c5c8c3466f6d00a76e7b4e24921b4d4e1286f.1636156453.git.v.shpilevoy@tarantool.org> Content-Language: en-GB In-Reply-To: <9a8c5c8c3466f6d00a76e7b4e24921b4d4e1286f.1636156453.git.v.shpilevoy@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9731B3922EC0639797E2FB9ED5E6B7867ED380939113F85C700894C459B0CD1B94B3B463BA353070D8B13D0E784B7980AAA1D1AB37C96470E408B34B1CBA95A7D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70D278D70F8433719EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637645995A778B1BFFAEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F23BDF17696A631728B6EAFB57737C75E4CC7F00164DA146DAFE8445B8C89999728AA50765F790063783E00425F71A4181389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8EDCF5861DED71B2F389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998ED8FC6C240DEA76428AA50765F790063704FE58BE7996079FD81D268191BDAD3DBD4B6F7A4D31EC0BEA7A3FFF5B025636D81D268191BDAD3D78DA827A17800CE7E3127721F5A72C97CD04E86FAF290E2D7E9C4E3C761E06A71DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6D75B66E98413B381089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B5050C315A302238E54BD7CE123554F22BE0 X-C1DE0DAB: 0D63561A33F958A5C384CCEF325CCD6393DD569C1DDE80972B5B677C9FAA6AF8D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753753CEE10E4ED4A7410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AB80C45F81B80D63B730031FA3B9C958453C073294950ECFE3FEFECEB2C31C4274288D065E5D9EDE1D7E09C32AA3244C70650F0C54747489FA785C949C237D07259227199D06760AFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj9/1IdNVT2RZsJq6Srks9Xg== X-Mailru-Sender: 11C2EC085EDE56FA38FD4C59F7EFE407B116CF526C2D7729C357C672CFE93D52F1BEAF8DD7A218106BB2E709EA627F343C7DDD459B58856F0E45BC603594F5A135B915D4279FF0579437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 8/9] luatest: add new helpers for 'server' object 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: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 06.11.2021 02:56, Vladislav Shpilevoy пишет: > -- Wait until the instance becomes an elected leader. > server:wait_election_leader() > > -- Wait until an election leader is found. > server:wait_election_leader_found() > > -- Get numeric ID of the instance like in box.info.id. > server:instance_id() > > -- Get UUID of the instance like in box.info.uuid. > server:instance_uuid() > > These are going to be used in a new test in a next commit. > --- > test/luatest_helpers/server.lua | 64 ++++++++++++++++++++++++++------- > 1 file changed, 52 insertions(+), 12 deletions(-) Hi! Thanks for working on this! Please, find a couple of small comments below. > > diff --git a/test/luatest_helpers/server.lua b/test/luatest_helpers/server.lua > index b6d6f1400..9959bca6c 100644 > --- a/test/luatest_helpers/server.lua > +++ b/test/luatest_helpers/server.lua > @@ -75,28 +75,45 @@ function Server:build_env() > return res > end > > -function Server:wait_for_readiness() > - local alias = self.alias > - local id = self.id > - local pid = self.process.pid > +local function wait_cond(cond_name, server, func, ...) > + local alias = server.alias > + local id = server.id > + local pid = server.process.pid > > local deadline = clock.time() + WAIT_TIMEOUT > while true do > - local ok, is_ready = pcall(function() > - self:connect_net_box() > - return self.net_box:eval('return _G.ready') == true > - end) > - if ok and is_ready then > - break > + if func(...) then > + return > end > if clock.time() > deadline then > - error(('Starting of server %s-%s (PID %d) was timed out'):format( > - alias, id, pid)) > + error(('Waiting for "%s" on server %s-%s (PID %d) timed out') > + :format(alias, id, pid)) 1. Looks like you forgot to use "cond_name" in the error message. > end > fiber.sleep(WAIT_DELAY) > end > end > > +function Server:wait_for_readiness() > + return wait_cond('readiness', self, function() > + local ok, is_ready = pcall(function() > + self:connect_net_box() > + return self.net_box:eval('return _G.ready') == true > + end) > + return ok and is_ready > + end) > +end > + > +function Server:wait_election_leader() > + return wait_cond('election leader', self, self.exec, self, function() > + return box.info.election.state == 'leader' > + end) > +end > + > +function Server:wait_election_leader_found() > + return wait_cond('election leader is found', self, self.exec, self, > + function() return box.info.election.leader ~= 0 end) > +end > + > -- Unlike the original luatest.Server function it waits for > -- starting the server. > function Server:start(opts) > @@ -116,6 +133,29 @@ function Server:start(opts) > end > end > > +function Server:instance_id() > + -- Cache the value when found it first time. > + if self.instance_id_value then > + return self.instance_id_value > + end > + local id = self:exec(function() return box.info.id end) > + -- But do not cache 0 - it is an anon instance, its ID might change. > + if id ~= 0 then > + self.instance_id_value = id > + end > + return id > +end 2. Let's reset cached instance id in Server:cleanup().    One might want to call Server:cleanup() and then restart the server    making it receive a new instance id. > + > +function Server:instance_uuid() > + -- Cache the value when found it first time. > + if self.instance_uuid_value then > + return self.instance_uuid_value > + end > + local uuid = self:exec(function() return box.info.uuid end) > + self.instance_uuid_value = uuid > + return uuid > +end > + > -- TODO: Add the 'wait_for_readiness' parameter for the restart() > -- method. > -- Serge Petrenko