From: Vladimir Davydov via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: tarantool-patches@dev.tarantool.org Cc: v.shpilevoy@tarantool.org, yaroslav.dynnikov@tarantool.org Subject: [Tarantool-patches] [PATCH v2] net.box: do not yield in future.wait_result(0) Date: Fri, 13 Aug 2021 15:14:51 +0300 [thread overview] Message-ID: <7b986fe9f451e1211b97d564ad6ed2ced048997f.1628856798.git.vdavydov@tarantool.org> (raw) In-Reply-To: <923e00dac8a59e44dc2a87d44385812ea9d38db0.1628850359.git.vdavydov@tarantool.org> It didn't yield before commit 954194a1ca5c ("net.box: rewrite request implementation in C"). It shouldn't yield now. Follow-up #6241 --- https://github.com/tarantool/tarantool/tree/vdavydov/netbox-dont-yield-in-future-wait-result-if-timeout-is-0 Changes in v2: - Improved test. src/box/lua/net_box.c | 2 + test/box/net.box_fiber-async_gh-3107.result | 48 +++++++++++++++++++ test/box/net.box_fiber-async_gh-3107.test.lua | 20 ++++++++ 3 files changed, 70 insertions(+) diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index 229dec590cf9..43a7d78a1122 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -235,6 +235,8 @@ netbox_request_complete(struct netbox_request *request) static inline bool netbox_request_wait(struct netbox_request *request, double *timeout) { + if (*timeout == 0) + return false; double ts = ev_monotonic_now(loop()); int rc = fiber_cond_wait_timeout(&request->cond, *timeout); *timeout -= ev_monotonic_now(loop()) - ts; diff --git a/test/box/net.box_fiber-async_gh-3107.result b/test/box/net.box_fiber-async_gh-3107.result index aaaca351a579..ec2fd4f6441a 100644 --- a/test/box/net.box_fiber-async_gh-3107.result +++ b/test/box/net.box_fiber-async_gh-3107.result @@ -104,6 +104,54 @@ err:find('Usage') ~= nil --- - true ... +-- +-- Check that there's no unexpected yields. +-- +function assert_no_csw(func, ...) \ + local csw1 = fiber.info()[fiber.id()].csw \ + local ret = {func(...)} \ + local csw2 = fiber.info()[fiber.id()].csw \ + assert(csw2 - csw1 == 0) \ + return unpack(ret) \ +end +--- +... +future = c:call('long_function', {1, 2, 3}, {is_async = true}) +--- +... +assert_no_csw(future.is_ready, future) +--- +- false +... +assert_no_csw(future.result, future) +--- +- null +- Response is not ready +... +assert_no_csw(future.wait_result, future, 0) +--- +- null +- Timeout exceeded +... +finalize_long() +--- +... +future:wait_result() +--- +- [1, 2, 3] +... +assert_no_csw(future.is_ready, future) +--- +- true +... +assert_no_csw(future.result, future) +--- +- [1, 2, 3] +... +assert_no_csw(future.wait_result, future) +--- +- [1, 2, 3] +... box.schema.func.drop('long_function') --- ... diff --git a/test/box/net.box_fiber-async_gh-3107.test.lua b/test/box/net.box_fiber-async_gh-3107.test.lua index d23f368cbce4..71ba50b62ccb 100644 --- a/test/box/net.box_fiber-async_gh-3107.test.lua +++ b/test/box/net.box_fiber-async_gh-3107.test.lua @@ -36,6 +36,26 @@ err:find('Usage') ~= nil _, err = pcall(future.wait_result, future, '100') err:find('Usage') ~= nil +-- +-- Check that there's no unexpected yields. +-- +function assert_no_csw(func, ...) \ + local csw1 = fiber.info()[fiber.id()].csw \ + local ret = {func(...)} \ + local csw2 = fiber.info()[fiber.id()].csw \ + assert(csw2 - csw1 == 0) \ + return unpack(ret) \ +end +future = c:call('long_function', {1, 2, 3}, {is_async = true}) +assert_no_csw(future.is_ready, future) +assert_no_csw(future.result, future) +assert_no_csw(future.wait_result, future, 0) +finalize_long() +future:wait_result() +assert_no_csw(future.is_ready, future) +assert_no_csw(future.result, future) +assert_no_csw(future.wait_result, future) + box.schema.func.drop('long_function') c:close() -- 2.25.1
next prev parent reply other threads:[~2021-08-13 12:14 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-13 10:27 [Tarantool-patches] [PATCH] " Vladimir Davydov via Tarantool-patches 2021-08-13 12:14 ` Vladimir Davydov via Tarantool-patches [this message] 2021-08-13 14:15 ` [Tarantool-patches] [PATCH v2] " Yaroslav Dynnikov via Tarantool-patches 2021-08-16 10:38 ` Vitaliia Ioffe via Tarantool-patches 2021-08-16 10:47 ` Vladimir Davydov via Tarantool-patches 2021-08-13 12:59 ` [Tarantool-patches] [PATCH] " Yaroslav Dynnikov via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=7b986fe9f451e1211b97d564ad6ed2ced048997f.1628856798.git.vdavydov@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --cc=vdavydov@tarantool.org \ --cc=yaroslav.dynnikov@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2] net.box: do not yield in future.wait_result(0)' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox