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 555ED70368; Mon, 18 Jan 2021 15:47:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 555ED70368 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1610974042; bh=ciHoPuT7K0oEm/SZN0GzYX0JenVjwJ8v00xYHs2Qow4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=cbN9+a2xqpkb8aH5s6T7kC68BMJvvX//fYsj9z9EHPU6z7+w3zLEXdLOvcGkZb9JU wWMh3P5ybrAAvpBwFo506foXpbyA0KubJ6IFcyx2PooXJWI/UxzTXTTJVQ+qkzn4cE 8weKRUJt3jBtNUByQ+ZCMOCQB6u7A2ugBTvvebMI= Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (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 2123784381 for ; Mon, 18 Jan 2021 15:45:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2123784381 Received: by smtp45.i.mail.ru with esmtpa (envelope-from ) id 1l1Tuq-0003iw-Nc; Mon, 18 Jan 2021 15:45:53 +0300 To: Alexander Turenko Date: Mon, 18 Jan 2021 15:45:42 +0300 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D0E79FBC973162CDDA1A336500443B3AD46BC604C28ED16A00894C459B0CD1B9194A5313BE4F06E72BB14DAA995B2F23392BE03B42F7614B89BD80B6B4489A2D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE742D9BD90C58D50E0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372A1456D053D20C618638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FCFE91D019DCCD3BAE014A0CE595D7EDA8CB7C7B239964B5EA389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B68424CA1AAF98A6958941B15DA834481F9449624AB7ADAF37BA3038C0950A5D3613377AFFFEAFD2691661749BA6B977358790B6C3D1E273807B076A6E789B0E97A8DF7F3B2552694A1E7802607F20496D49FD398EE364050F7B96B19DC4093321CAA9C333723BB66AB3661434B16C20AC78D18283394535A975ECD9A6C639B01BC09775C1D3CA48CFD959F89D3055010035872C767BF85DA22EF20D2F80756B5F40A5AABA2AD3711975ECD9A6C639B01B78DA827A17800CE70AF187660F8F25A4731C566533BA786A40A5AABA2AD371193C9F3DD0FB1AF5EB82E77451A5C57BD33C9F3DD0FB1AF5EB4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C8F59B88ADF80E5C03C13731CB5C596087892B1BAC68DDA409C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF6EA1BA7CA28B4A74699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D348B409C2D257583DFB8EE696B6934FFE12246454204D23252332D8E88F46CB6C890A83DDE248FEAC51D7E09C32AA3244C2BD81EC85AB3CE05D9A0F04F348A0CB1A8CE788DE683120583B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojYu4DkwLgf0KKT0s+TFbHpg== X-Mailru-Sender: 65CD03CFE33A0EC7A4D6F6B2DF798FE64CA8257CBFB8F2C082507CFA26FCE22FCDEF86246319806DB08A37556DE0CB7BB7E364AFDB3F206FD953F29DB7D76D89B1E6F68DAE724AB9112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCHv4 3/3] test: change -e assert(false) test using process_timeout module 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: Artem Starshov via Tarantool-patches Reply-To: Artem Starshov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Removed definitions of functions with timeout. Now they are used from separated module process_timeout.lua Follows up #4983 --- .../gh-4983-tnt-e-assert-false-hangs.test.lua | 62 +++---------------- 1 file changed, 9 insertions(+), 53 deletions(-) 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 c8313770e..20046d7a5 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() -- 2.28.0