[Tarantool-patches] [PATCH 8/9] luatest: add new helpers for 'server' object

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Nov 12 02:51:05 MSK 2021


Thanks for the review!

>> 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.

====================
Yes indeed, thanks for noticing:

             error(('Waiting for "%s" on server %s-%s (PID %d) timed out')
-                  :format(alias, id, pid))
+                  :format(cond_name, alias, id, pid))
         end
====================

>> @@ -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.

Thanks, done:

====================
@@ -186,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
====================


More information about the Tarantool-patches mailing list