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 9784A7030F; Fri, 15 Jan 2021 12:38:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9784A7030F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1610703496; bh=GsW7gCvHI+GC8tMoc8yI/zCyXC15+74trZG0DHLY/yY=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=CheA/vfKEIxbXWn5iSdYvG98G3AOXc4MeeRm0f34YwExuUD/mUxfrg/vJfHFA6N6H X0VU2keUgGmUWyfqYrvkbsp3BE3+co2mPExJwb5KOCTSEQpZr1qqC0x+hbZjRwZAyG q6mQxOzZyOZxLfogDBZcj01gnxVhLrf/tbdfqUqI= Received: from smtp38.i.mail.ru (smtp38.i.mail.ru [94.100.177.98]) (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 76B697030F for ; Fri, 15 Jan 2021 12:38:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 76B697030F Received: by smtp38.i.mail.ru with esmtpa (envelope-from ) id 1l0LYb-0006bI-9W; Fri, 15 Jan 2021 12:38:13 +0300 To: Artem Starshov , Alexander Turenko References: Message-ID: <2081317d-2367-3281-9d3c-f7ac0e67b105@tarantool.org> Date: Fri, 15 Jan 2021 12:37:57 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9D0E79FBC973162CDC332107C56D78A30EABAEB9DEE13ADFC00894C459B0CD1B960E9307D7F3E62C8A1C79B969BBA33D282B5DE69E09FD754EA0974AE69F90BDD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7BCC85671EC7A750CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EF59B520676799BC8638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC5C32F25192867AFC5CEC69AFA67124CBC6F13DC69EF24726389733CBF5DBD5E913377AFFFEAFD269A417C69337E82CC2CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92A417C69337E82CC2CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C22490EF8A097A92E1CE276E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8B7AABBC3B12AC6BCD3AA81AA40904B5D9DBF02ECDB25306B2B25CBF701D1BE8734AD6D5ED66289B5278DA827A17800CE79E6B27D82EEA174F67F23339F89546C5A8DF7F3B2552694A6FED454B719173D6725E5C173C3A84C33EA25F22EA74352D35872C767BF85DA2F004C906525384306FED454B719173D6462275124DF8B9C9DE2850DD75B2526BE5BFE6E7EFDEDCD789D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5B3974B379A79A55D22D2343CCFD073658FFB2A0F5A613E82D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA758F9E841AEAEC4F2C410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D6AC337C1E637B8A2A7464DDE54C159B5A209A2283FF75EB99DAAD9E14733263D3E3E8B889BD04491D7E09C32AA3244C1BF1BD48D0344CD607CD7D99B6106388E646F07CC2D4F3D8927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojT/h6YDL0UQ4pMEYZ+ZIwdA== X-Mailru-Sender: 48EFD2E18A91C559803250E574CC3D295AD374C87D04A30300310FAFE6E4596BEFC4EB6826DC2248D35D514C7DAC97282D063C67CFD4E84987597EC79699C0E6F21BD4036121A32F7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCHv3 2/2] test: move helper functions to separated module in -e assert(false) test 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: Leonid Vasiliev via Tarantool-patches Reply-To: Leonid Vasiliev Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thank you for the patch. LGTM. See some comments below: > "test: move helper functions to separated module in -e assert(false) test" May be "... from -e assert(false) test"? On 14.01.2021 12:45, Artem Starshov wrote: > Functions with timeout transferred to module > test/app-tap/lua/process_timeout.lua for further > using in other tests. > > Before this version of test was already done, > but by mistake older version was rebased on > master. I don't think this information is significant for the history. Up to you. > > Follows up #4983 > --- > from https://lists.tarantool.org/pipermail/tarantool-patches/2020-December/021895.html : > "2) No external function currently uses this function. > I suggest removing it from the interface." > > I'd like to leave `process_is_alive`, because it's really useful > function, it's already needed in `-e enters interactive mode` > test. Ok. > > .../gh-4983-tnt-e-assert-false-hangs.test.lua | 62 +++---------------- > test/app-tap/lua/process_timeout.lua | 57 +++++++++++++++++ > test/app-tap/suite.ini | 2 +- > 3 files changed, 67 insertions(+), 54 deletions(-) > create mode 100644 test/app-tap/lua/process_timeout.lua > > diff --git a/test/app-tap/gh-4983-tnt-e-assert-false-hangs.test.lua b/test/app-tap/gh-4983-tnt-e-assert-false-hangs.test.lua > index d259f37fd..2978a6203 100755 > --- a/test/app-tap/gh-4983-tnt-e-assert-false-hangs.test.lua > +++ b/test/app-tap/gh-4983-tnt-e-assert-false-hangs.test.lua > @@ -1,61 +1,17 @@ > #!/usr/bin/env tarantool > > -local fiber = require('fiber') > -local clock = require('clock') > -local ffi = require('ffi') > -local fio = require('fio') > -local errno = require('errno') > +-- Using io.popen and self written module process_timeout > +-- in presence of the 'popen' built-in module because the > +-- last one isn't available in 1.10 > +local process_timeout = require('process_timeout') > local tap = require('tap') > +local fio = require('fio') > +local ffi = require('ffi') > > -- > -- gh-4983: tarantool -e 'assert(false)' hangs > -- > > --- For process_is_alive. > -ffi.cdef([[ > - int kill(pid_t pid, int sig); > -]]) > - > ---- Verify whether a process is alive. > -local function process_is_alive(pid) > - local rc = ffi.C.kill(pid, 0) > - return rc == 0 or errno() ~= errno.ESRCH > -end > - > ---- Returns true if process completed before timeout, false otherwise. > -local function wait_process_completion(pid, timeout) > - local start_time = clock.monotonic() > - local process_completed = false > - while clock.monotonic() - start_time < timeout do > - if not process_is_alive(pid) then > - process_completed = true > - break > - end > - end > - return process_completed > -end > - > ---- Open file on reading with timeout. > -local function open_with_timeout(filename, timeout) > - local fh > - local start_time = clock.monotonic() > - while not fh and clock.monotonic() - start_time < timeout do > - fh = fio.open(filename, {'O_RDONLY'}) > - end > - return fh > -end > - > ---- Try to read from file with timeout with interval. > -local function read_with_timeout(fh, timeout, interval) > - local data = '' > - local start_time = clock.monotonic() > - while #data == 0 and clock.monotonic() - start_time < timeout do > - data = fh:read() > - if #data == 0 then fiber.sleep(interval) end > - end > - return data > -end > - > local TARANTOOL_PATH = arg[-1] > local output_file = fio.abspath('out.txt') > local line = ('%s -e "assert(false)" > %s 2>&1 & echo $!'): > @@ -73,7 +29,7 @@ local res = tap.test('gh-4983-tnt-e-assert-false-hangs', function(test) > local pid = tonumber(io.popen(line):read('*line')) > assert(pid, 'pid of proccess can\'t be recieved') > > - local process_completed = wait_process_completion(pid, > + local process_completed = process_timeout.wait_process_completion(pid, > process_waiting_timeout) > > test:ok(process_completed, > @@ -82,10 +38,10 @@ local res = tap.test('gh-4983-tnt-e-assert-false-hangs', function(test) > -- Kill process if hangs. > if not process_completed then ffi.C.kill(pid, 9) end > > - local fh = open_with_timeout(output_file, file_open_timeout) > + local fh = process_timeout.open_with_timeout(output_file, file_open_timeout) > assert(fh, 'error while opening ' .. output_file) > > - local data = read_with_timeout(fh, file_read_timeout, file_read_interval) > + local data = process_timeout.read_with_timeout(fh, file_read_timeout, file_read_interval) > test:like(data, 'assertion failed', 'assertion failure is displayed') > > fh:close() > diff --git a/test/app-tap/lua/process_timeout.lua b/test/app-tap/lua/process_timeout.lua > new file mode 100644 > index 000000000..141fb0e43 > --- /dev/null > +++ b/test/app-tap/lua/process_timeout.lua > @@ -0,0 +1,57 @@ > +local fiber = require('fiber') > +local clock = require('clock') > +local ffi = require('ffi') > +local fio = require('fio') > +local errno = require('errno') > + > +-- For process_is_alive. > +ffi.cdef([[ > + int kill(pid_t pid, int sig); > +]]) > + > +--- Verify whether a process is alive. > +local function process_is_alive(pid) > + local rc = ffi.C.kill(pid, 0) > + return rc == 0 or errno() ~= errno.ESRCH > +end > + > +--- Returns true if process completed before timeout, false otherwise. > +local function wait_process_completion(pid, timeout) > + local start_time = clock.monotonic() > + local process_completed = false > + while clock.monotonic() - start_time < timeout do > + if not process_is_alive(pid) then > + process_completed = true > + break > + end > + end > + return process_completed > +end > + > +--- Open file on reading with timeout. > +local function open_with_timeout(filename, timeout) > + local fh > + local start_time = clock.monotonic() > + while not fh and clock.monotonic() - start_time < timeout do > + fh = fio.open(filename, {'O_RDONLY'}) > + end > + return fh > +end > + > +--- Try to read from file with timeout with interval. > +local function read_with_timeout(fh, timeout, interval) > + local data = '' > + local start_time = clock.monotonic() > + while #data == 0 and clock.monotonic() - start_time < timeout do > + data = fh:read() > + if #data == 0 then fiber.sleep(interval) end > + end > + return data > +end > + > +return { > + process_is_alive = process_is_alive, > + wait_process_completion = wait_process_completion, > + open_with_timeout = open_with_timeout, > + read_with_timeout = read_with_timeout > +} > diff --git a/test/app-tap/suite.ini b/test/app-tap/suite.ini > index 2f16128f9..6e27f88d6 100644 > --- a/test/app-tap/suite.ini > +++ b/test/app-tap/suite.ini > @@ -1,7 +1,7 @@ > [default] > core = app > description = application server tests (TAP) > -lua_libs = lua/require_mod.lua lua/serializer_test.lua > +lua_libs = lua/require_mod.lua lua/serializer_test.lua lua/process_timeout.lua > is_parallel = True > pretest_clean = True > use_unix_sockets_iproto = True >