From 7b4eb172de68ea6d77e1230eb85926be238c2701 Mon Sep 17 00:00:00 2001 From: Vladimir Davydov <vdavydov@tarantool.org> Date: Fri, 13 Aug 2021 13:24:27 +0300 Subject: [PATCH] net.box: do not yield in future.wait_result(0) It didn't yield before commit 954194a1ca5c ("net.box: rewrite request implementation in C"). It shouldn't yield now. Follow-up #6241 --- 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 229dec590c..43a7d78a11 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 aaaca351a5..ec2fd4f644 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 d23f368cbc..71ba50b62c 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() -- GitLab