From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org
Subject: [Tarantool-patches] [PATCH v2 09/11] luatest: add new helpers for 'server' object
Date: Fri, 12 Nov 2021 00:54:30 +0100 [thread overview]
Message-ID: <21dd421286bcadf3a3fd4188c8149cfcce1902a5.1636674803.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1636674803.git.v.shpilevoy@tarantool.org>
-- 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)
next prev parent reply other threads:[~2021-11-12 0:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-11 23:54 [Tarantool-patches] [PATCH v2 00/11] ER_READONLY reason Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 01/11] diag: return created error from diag_set() Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 10/11] box: enrich ER_READONLY with new details Vladislav Shpilevoy via Tarantool-patches
2021-11-12 7:30 ` Serge Petrenko via Tarantool-patches
2021-11-12 23:24 ` Vladislav Shpilevoy via Tarantool-patches
2021-11-15 6:51 ` Serge Petrenko via Tarantool-patches
2021-11-15 21:56 ` Vladislav Shpilevoy via Tarantool-patches
2021-11-16 9:53 ` Serge Petrenko via Tarantool-patches
2021-11-16 22:08 ` Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 11/11] error: report ER_READONLY reason in message Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 02/11] uuid: move into libcore Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 03/11] error: introduce error_payload Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 04/11] error: move code to struct error from ClientError Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 05/11] error: use error_payload to store optional members Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 06/11] error: use error_payload in MessagePack codecs Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 07/11] error: use error_payload in Lua Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` [Tarantool-patches] [PATCH v2 08/11] luatest: copy config in cluster:build_server() Vladislav Shpilevoy via Tarantool-patches
2021-11-11 23:54 ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-11-12 23:25 ` [Tarantool-patches] [PATCH v2 12/11] error: introduce box.info.ro_reason Vladislav Shpilevoy via Tarantool-patches
2021-11-15 6:53 ` Serge Petrenko via Tarantool-patches
2021-11-16 22:08 ` [Tarantool-patches] [PATCH v2 00/11] ER_READONLY reason Vladislav Shpilevoy via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=21dd421286bcadf3a3fd4188c8149cfcce1902a5.1636674803.git.v.shpilevoy@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=sergepetrenko@tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v2 09/11] luatest: add new helpers for '\''server'\'' object' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox