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 587F170310; Wed, 27 Jan 2021 02:37:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 587F170310 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611704264; bh=YD/fmJZa+0n02g866QlpKsO51LHtmWUx+k+O2//VV4E=; 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=leOVZ/Q77xYq731jLpk4SDQi5YInYzJ3KdJslhn6TAjlkcr/HPrtEdGyb5Y7lLkdg KeSQUpPsnMB983362VD2fH/yN7tBMGxzhNMoq4J8NYQL3UPGGzNgKNh7EQsG7lUOis VLgfvliLDEZBRirDB7cBUIRD8eIoL+/dGTkBj55Q= Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (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 9B15870310 for ; Wed, 27 Jan 2021 02:37:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9B15870310 Received: by smtp39.i.mail.ru with esmtpa (envelope-from ) id 1l4XtY-0002oP-Bz; Wed, 27 Jan 2021 02:37:12 +0300 To: Alexander Turenko Date: Wed, 27 Jan 2021 02:37:06 +0300 Message-Id: <42e2bcfb1f7cf6b227c72c1da2ade8653d953fbc.1611702978.git.artemreyt@tarantool.org> 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: 4F1203BC0FB41BD92BC6D7A73B5E1EC98EC91D74BAC48C3C5ED0B073A515FC4C00894C459B0CD1B9653E3E6C8BBAE5C8B0251C9BBD33545579EEC448202F985355057FA91F6F9B79 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7EC0B1A4921CAE631EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378D64EDD178B2A1008638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC1223A9679A0740CBAFC2022A7FE7F4F9874F2A7313C4F5EC389733CBF5DBD5E913377AFFFEAFD269A417C69337E82CC2CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92A417C69337E82CC2CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249B2D5CF8B95DD2E8A76E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8BED9D2A60863C8C1E3AA81AA40904B5D9DBF02ECDB25306B2B25CBF701D1BE8734AD6D5ED66289B5278DA827A17800CE760822658196F8C5A67F23339F89546C5A8DF7F3B2552694A6FED454B719173D6725E5C173C3A84C3705BB8FF2EA96B1B35872C767BF85DA2F004C906525384306FED454B719173D6462275124DF8B9C9DE2850DD75B2526BE5BFE6E7EFDEDCD789D4C264860C145E X-B7AD71C0: 14C14B24D00AF5AC321EF223B8115265C69B993890792DF82CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D3DC4C67AC47ABCAF355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CEC4A33FB89DC571C85203D44DB64D5320BCCDC84BEE83F299C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFF532FBFD8162E58C699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3488E5CD2E691F5566FBDB44F0340D15C40822612D87E48FA39C66C79EB5B2ADF45753E9B2B7B576E01D7E09C32AA3244C426EC23211F642F662DA54FC47D9582E858039643087248083B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj5ZUBkD5pAd8YFpiNj9aMVA== X-Mailru-Sender: 65CD03CFE33A0EC7A4D6F6B2DF798FE60C211C0914160BD79F4CC9202EF80AD24096A02700950005B08A37556DE0CB7BB7E364AFDB3F206FD953F29DB7D76D89B1E6F68DAE724AB9112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 1/3] test: add separated module for proccess operations with timeout 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" Functions with timeout transferred to module test/app-tap/lua/process_timeout.lua for further using in other tests. (from test/app-tap/gh-4983-tnt-e-assert-false-hangs.test.lua) Follows up #4983 --- test/app-tap/lua/process_timeout.lua | 59 ++++++++++++++++++++++++++++ test/app-tap/suite.ini | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/app-tap/lua/process_timeout.lua diff --git a/test/app-tap/lua/process_timeout.lua b/test/app-tap/lua/process_timeout.lua new file mode 100644 index 000000000..1ca3636b9 --- /dev/null +++ b/test/app-tap/lua/process_timeout.lua @@ -0,0 +1,59 @@ +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 + fiber.sleep(0.01) + 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'}) + fiber.sleep(0.01) + 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 -- 2.28.0