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 D5BE26CE33; Sat, 6 Nov 2021 03:00:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D5BE26CE33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636156853; bh=sZcQcm3lDnAt8fKgyoLlPKoQBGTKP92AqRJMftKxK3M=; 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=ofN5fp6gGC07U2CwdIQnALjHeTlz8W3FRPfj9AU3CjyKSwLFp4FQ7iAbdPGrcFKYR Yiqc4Qbu2Sebk1PpwINmGHdSOYZAnl88l79Gu1mq5OAovLA+g+tVcpeVOiR2HCRibE mc9KwN1siPvlAVhu5fMk9k/EWFImYyZL5WHAjNQI= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (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 CD8C86CE33 for ; Sat, 6 Nov 2021 02:56:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CD8C86CE33 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1mj94l-0006s6-Lw; Sat, 06 Nov 2021 02:56:52 +0300 To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org, vdavydov@tarantool.org Date: Sat, 6 Nov 2021 00:56:39 +0100 Message-Id: <9a8c5c8c3466f6d00a76e7b4e24921b4d4e1286f.1636156453.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: 4F1203BC0FB41BD9F9D976862A30D4FE61DAF562F6772BE82A7A53D19C82BF04182A05F538085040D6D951DD76CE54F97F91F44F3A7F895C9A15DCFCFBBE51848C97CDCAA391F80D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AED985C8E545F588EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637204D59D994DFFAD78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D85A72C1377F21730CA34E8195B8975C9A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CD1D040B6C1ECEA3F43847C11F186F3C59DAA53EE0834AAEE X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505F04FA6A337665710B09F1B457752A255 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E8FD95C1B0C506BFF233F3D496764900040BEBE33BB939A9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFFA31AF570DAA8E08699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D95739AEDB3821B4198D3CC9E606868F982938C01C33375254B366ABC6102FC1A1CB5017F07A20811D7E09C32AA3244C8214C6E41FAE9E896A97796537E6F80CE8FBBEFAE1C4874CFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXh381GlVXuKwcDiikVNr2AJ X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D13D76F19AF8D48FA61B941E35FA81A6E3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [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: 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 | 64 ++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 12 deletions(-) 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)) 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. -- 2.24.3 (Apple Git-128)