* [Tarantool-patches] [PATCHv3 0/2] test: -e assert(false) test fixup @ 2021-01-14 9:45 Artem Starshov via Tarantool-patches 2021-01-14 9:45 ` [Tarantool-patches] [PATCHv3 1/2] test: increase timeout in -e assert(false) test Artem Starshov via Tarantool-patches 2021-01-14 9:45 ` [Tarantool-patches] [PATCHv3 2/2] test: move helper functions to separated module " Artem Starshov via Tarantool-patches 0 siblings, 2 replies; 6+ messages in thread From: Artem Starshov via Tarantool-patches @ 2021-01-14 9:45 UTC (permalink / raw) To: Alexander Turenko; +Cc: tarantool-patches Changes in v2: - changed commit message name - added 'follows up #4983' - removed collecting details about process due to Linux specific - left only the last commit because the previous was pushed to master and the first one is empty after the review - added comment describing the reason of using timeout module in presence of built-in 'popen' module Changes in v3: - split one commit into two: first - increase timeout, second - move helper functions to separated module Branch: https://github.com/tarantool/tarantool/tree/artemreyt/gh-4983-fix-test Artem Starshov (2): test: increase timeout in -e assert(false) test test: move helper functions to separated module in -e assert(false) test .../gh-4983-tnt-e-assert-false-hangs.test.lua | 72 ++++--------------- test/app-tap/lua/process_timeout.lua | 57 +++++++++++++++ test/app-tap/suite.ini | 2 +- 3 files changed, 73 insertions(+), 58 deletions(-) create mode 100644 test/app-tap/lua/process_timeout.lua -- 2.28.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Tarantool-patches] [PATCHv3 1/2] test: increase timeout in -e assert(false) test 2021-01-14 9:45 [Tarantool-patches] [PATCHv3 0/2] test: -e assert(false) test fixup Artem Starshov via Tarantool-patches @ 2021-01-14 9:45 ` Artem Starshov via Tarantool-patches 2021-01-15 9:13 ` Leonid Vasiliev via Tarantool-patches 2021-01-15 9:17 ` Leonid Vasiliev via Tarantool-patches 2021-01-14 9:45 ` [Tarantool-patches] [PATCHv3 2/2] test: move helper functions to separated module " Artem Starshov via Tarantool-patches 1 sibling, 2 replies; 6+ messages in thread From: Artem Starshov via Tarantool-patches @ 2021-01-14 9:45 UTC (permalink / raw) To: Alexander Turenko; +Cc: tarantool-patches Set timeout to 60 sec for waiting operations with process, like in default timeout for `cond_wait` in test-run. --- test/app-tap/gh-4983-tnt-e-assert-false-hangs.test.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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 656fe212b..d259f37fd 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 @@ -60,10 +60,12 @@ local TARANTOOL_PATH = arg[-1] local output_file = fio.abspath('out.txt') local line = ('%s -e "assert(false)" > %s 2>&1 & echo $!'): format(TARANTOOL_PATH, output_file) -local process_waiting_timeout = 30.0 -local file_read_timeout = 30.0 -local file_read_interval = 0.2 -local file_open_timeout = 30.0 + +-- Like a default timeout for `cond_wait` in test-run +local process_waiting_timeout = 60.0 +local file_read_timeout = 60.0 +local file_open_timeout = 60.0 +local file_read_interval = 0.01 local res = tap.test('gh-4983-tnt-e-assert-false-hangs', function(test) test:plan(2) -- 2.28.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Tarantool-patches] [PATCHv3 1/2] test: increase timeout in -e assert(false) test 2021-01-14 9:45 ` [Tarantool-patches] [PATCHv3 1/2] test: increase timeout in -e assert(false) test Artem Starshov via Tarantool-patches @ 2021-01-15 9:13 ` Leonid Vasiliev via Tarantool-patches 2021-01-15 9:17 ` Leonid Vasiliev via Tarantool-patches 1 sibling, 0 replies; 6+ messages in thread From: Leonid Vasiliev via Tarantool-patches @ 2021-01-15 9:13 UTC (permalink / raw) To: Artem Starshov, Alexander Turenko; +Cc: tarantool-patches Hi! Thank you from the patch. Generally LGTM. See some comments below: On 14.01.2021 12:45, Artem Starshov wrote: > Set timeout to 60 sec for waiting operations with process, > like in default timeout for `cond_wait` in test-run. > --- > test/app-tap/gh-4983-tnt-e-assert-false-hangs.test.lua | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 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 656fe212b..d259f37fd 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 > @@ -60,10 +60,12 @@ local TARANTOOL_PATH = arg[-1] > local output_file = fio.abspath('out.txt') > local line = ('%s -e "assert(false)" > %s 2>&1 & echo $!'): > format(TARANTOOL_PATH, output_file) > -local process_waiting_timeout = 30.0 > -local file_read_timeout = 30.0 > -local file_read_interval = 0.2 > -local file_open_timeout = 30.0 > + > +-- Like a default timeout for `cond_wait` in test-run > +local process_waiting_timeout = 60.0 > +local file_read_timeout = 60.0 > +local file_open_timeout = 60.0 > +local file_read_interval = 0.01 The change is not corresponded with the commit title (this is a decrease the timeout) and commit message. Please update the commit message or move this change to a separate commit (as for me, the first is preferable). > > local res = tap.test('gh-4983-tnt-e-assert-false-hangs', function(test) > test:plan(2) > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Tarantool-patches] [PATCHv3 1/2] test: increase timeout in -e assert(false) test 2021-01-14 9:45 ` [Tarantool-patches] [PATCHv3 1/2] test: increase timeout in -e assert(false) test Artem Starshov via Tarantool-patches 2021-01-15 9:13 ` Leonid Vasiliev via Tarantool-patches @ 2021-01-15 9:17 ` Leonid Vasiliev via Tarantool-patches 1 sibling, 0 replies; 6+ messages in thread From: Leonid Vasiliev via Tarantool-patches @ 2021-01-15 9:17 UTC (permalink / raw) To: Artem Starshov, Alexander Turenko; +Cc: tarantool-patches On 14.01.2021 12:45, Artem Starshov wrote: > Set timeout to 60 sec for waiting operations with process, > like in default timeout for `cond_wait` in test-run. Follows up #4983 > --- > test/app-tap/gh-4983-tnt-e-assert-false-hangs.test.lua | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 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 656fe212b..d259f37fd 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 > @@ -60,10 +60,12 @@ local TARANTOOL_PATH = arg[-1] > local output_file = fio.abspath('out.txt') > local line = ('%s -e "assert(false)" > %s 2>&1 & echo $!'): > format(TARANTOOL_PATH, output_file) > -local process_waiting_timeout = 30.0 > -local file_read_timeout = 30.0 > -local file_read_interval = 0.2 > -local file_open_timeout = 30.0 > + > +-- Like a default timeout for `cond_wait` in test-run > +local process_waiting_timeout = 60.0 > +local file_read_timeout = 60.0 > +local file_open_timeout = 60.0 > +local file_read_interval = 0.01 > > local res = tap.test('gh-4983-tnt-e-assert-false-hangs', function(test) > test:plan(2) > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Tarantool-patches] [PATCHv3 2/2] test: move helper functions to separated module in -e assert(false) test 2021-01-14 9:45 [Tarantool-patches] [PATCHv3 0/2] test: -e assert(false) test fixup Artem Starshov via Tarantool-patches 2021-01-14 9:45 ` [Tarantool-patches] [PATCHv3 1/2] test: increase timeout in -e assert(false) test Artem Starshov via Tarantool-patches @ 2021-01-14 9:45 ` Artem Starshov via Tarantool-patches 2021-01-15 9:37 ` Leonid Vasiliev via Tarantool-patches 1 sibling, 1 reply; 6+ messages in thread From: Artem Starshov via Tarantool-patches @ 2021-01-14 9:45 UTC (permalink / raw) To: Alexander Turenko; +Cc: tarantool-patches 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. 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. .../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 -- 2.28.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Tarantool-patches] [PATCHv3 2/2] test: move helper functions to separated module in -e assert(false) test 2021-01-14 9:45 ` [Tarantool-patches] [PATCHv3 2/2] test: move helper functions to separated module " Artem Starshov via Tarantool-patches @ 2021-01-15 9:37 ` Leonid Vasiliev via Tarantool-patches 0 siblings, 0 replies; 6+ messages in thread From: Leonid Vasiliev via Tarantool-patches @ 2021-01-15 9:37 UTC (permalink / raw) To: Artem Starshov, Alexander Turenko; +Cc: 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 > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-15 9:38 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-01-14 9:45 [Tarantool-patches] [PATCHv3 0/2] test: -e assert(false) test fixup Artem Starshov via Tarantool-patches 2021-01-14 9:45 ` [Tarantool-patches] [PATCHv3 1/2] test: increase timeout in -e assert(false) test Artem Starshov via Tarantool-patches 2021-01-15 9:13 ` Leonid Vasiliev via Tarantool-patches 2021-01-15 9:17 ` Leonid Vasiliev via Tarantool-patches 2021-01-14 9:45 ` [Tarantool-patches] [PATCHv3 2/2] test: move helper functions to separated module " Artem Starshov via Tarantool-patches 2021-01-15 9:37 ` Leonid Vasiliev via Tarantool-patches
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox