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 200826FFBB; Fri, 12 Nov 2021 03:00:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 200826FFBB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636675213; bh=SvjCNQJu2bJqgkYVHNcnnB1zOkD+78Wb7XgYr3wh0Zk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aNZG3hqMByuIHeDeHEkbzcwrwLOMOYhfW8wU9XRt9jjF38Aq2cRsvv8q7+F/mn/p6 RbWNYFSgZZApZZfxgyIGL3ZQkUq7nZIr6OH8dYIjiCdJ+Q73iSudmfStMDx3bkMmpW 6AokSp/tVRc2xNsqUqyR42hLHnqto5hkh/CgdRMA= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 1923F70658 for ; Fri, 12 Nov 2021 02:54:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1923F70658 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mlJu2-0003tY-6q; Fri, 12 Nov 2021 02:54:46 +0300 To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org Date: Fri, 12 Nov 2021 00:54:30 +0100 Message-Id: <21dd421286bcadf3a3fd4188c8149cfcce1902a5.1636674803.git.v.shpilevoy@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9731B3922EC0639792B05E85F1235528D4452084448829B2800894C459B0CD1B9B675325E0D6C49AB3EB16DD2F3357CC37F76FE7EF67E38FF50B51C660DE91301 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7922E451CE6E839B1EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637204D59D994DFFAD78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8FD5F91B28DDA14F5D9D6027C26FB7793117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CE31A2885C41F97C443847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9FEBB9C11794A1F1E4BBD558E7208AC0E96C3D8F15437D9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF11E5B64A728E1589699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C53D1911AD7E41990BE116AADE458575ABA260F5E1AEF0D876E12DA22F80A3332571D8354CAEDBD91D7E09C32AA3244C9C3342879C7962BF3034299DD4F92D7D435BF7150578642F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4t8MBgWr8bKqObRYaFGShw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D6BAD1653883DB3562DA9D4C0B55AB4753841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 09/11] 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" -- 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 | 66 +++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/test/luatest_helpers/server.lua b/test/luatest_helpers/server.lua index b6d6f1400..900db2243 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(cond_name, alias, id, pid)) 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 + +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. @@ -146,6 +186,8 @@ function Server:cleanup() for _, pattern in ipairs(DEFAULT_CHECKPOINT_PATTERNS) do fio.rmtree(('%s/%s'):format(self.workdir, pattern)) end + self.instance_id_value = nil + self.instance_uuid_value = nil end function Server:drop() -- 2.24.3 (Apple Git-128)