From 5893d61d9250e7e619a8509529816192bd9f89cd Mon Sep 17 00:00:00 2001 From: Serge Petrenko <sergepetrenko@tarantool.org> Date: Tue, 17 May 2022 16:10:35 +0300 Subject: [PATCH] net.box: introduce _inject remote method The inject remote method is used in testing quite a lot. For example, when someone needs to pass arbitrary MsgPack to Tarantool. The current way to use it is: conn:_request(netbox._method.inject, opts, nil, nil, custom_msgpack) This is quite long and ugly, so let's add a helper: conn:_inject(custom_msgpack, opts) Also, while we're at it, lets fix the following issue. The _inject remote method is barely usable without knowing which sync net.box will use for the next request. On the one hand, the user has to encode some custom sync to the request he's injecting. On the other hand, net.box doesn't parse the custom sync and always uses its own pre-generated one to wait for the request response. So the user has to pick the correct sync value, which net.box uses internally. Let's make life simpler and introduce _next_sync method, which returns the next sync, which will be used by net.box. In-scope-of #6857 Closes #7177 NO_DOC=internal change NO_CHANGELOG=internal change NO_TEST=tested implicitly in next commit --- src/box/lua/net_box.c | 9 +++++++++ src/box/lua/net_box.lua | 8 ++++++++ test/box-luatest/gh_6305_net_box_autocomplete_test.lua | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index 5efc67b372..d79f90fd97 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -2749,6 +2749,14 @@ luaT_netbox_transport_stop(struct lua_State *L) return 0; } +static int +luaT_netbox_transport_next_sync(struct lua_State *L) +{ + struct netbox_transport *transport = luaT_check_netbox_transport(L, 1); + luaL_pushuint64(L, transport->next_sync); + return 1; +} + /** * Puts an active connection to 'graceful_shutdown' state, in which no new * requests are allowed. The connection will be switched to the error state @@ -2793,6 +2801,7 @@ luaopen_net_box(struct lua_State *L) { "__gc", luaT_netbox_transport_gc }, { "start", luaT_netbox_transport_start }, { "stop", luaT_netbox_transport_stop }, + { "next_sync", luaT_netbox_transport_next_sync }, { "graceful_shutdown", luaT_netbox_transport_graceful_shutdown }, { "perform_request", diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 5e4c8d5938..c08fb02ac5 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -748,6 +748,14 @@ function remote_methods:_request(method, opts, format, stream_id, ...) return res end +function remote_methods:_inject(str, opts) + return self:_request(M_INJECT, opts, nil, nil, str) +end + +function remote_methods:_next_sync() + return self._transport:next_sync() +end + function remote_methods:ping(opts) check_remote_arg(self, 'ping') return (pcall(self._request, self, M_PING, opts, nil, self._stream_id)) diff --git a/test/box-luatest/gh_6305_net_box_autocomplete_test.lua b/test/box-luatest/gh_6305_net_box_autocomplete_test.lua index 2b4fd42ba3..5976a02312 100644 --- a/test/box-luatest/gh_6305_net_box_autocomplete_test.lua +++ b/test/box-luatest/gh_6305_net_box_autocomplete_test.lua @@ -37,12 +37,12 @@ g.test_autocomplete = function() 'conn1:watch(', 'conn1:call_16(', 'conn1:execute(', - 'conn1:prepare(', 'conn1:wait_state(', + 'conn1:ping(', 'conn1:unprepare(', + 'conn1:prepare(', 'conn1:close(', 'conn1:on_connect(', - 'conn1:ping(', 'conn1:new_stream(', 'conn1:is_connected(', 'conn1:eval(', -- GitLab