Tarantool development patches archive
 help / color / mirror / Atom feed
From: Maria <maria.khaydich@tarantool.org>
To: tarantool-patches@dev.tarantool.org, imun@tarantool.org,
	v.shpilevoy@tarantool.org
Subject: [Tarantool-patches] [PATCH] box: netbox.self and connect should work interchangeably
Date: Fri, 17 Jan 2020 20:08:01 +0300	[thread overview]
Message-ID: <20200117170801.34975-1-maria.khaydich@tarantool.org> (raw)

Despite what was stated in the documentation, netbox.connect was not always
equivalent to netbox.self. In particular, they converted tuple to different
types - table and cdata respectively.

The patch fixes the issue and covers all cases where netbox.self and connect
perform conversion of types - e.g., for box.error.

Closes #4513
---
Branch:
https://github.com/tarantool/tarantool/compare/eljashm/gh-4513-netbox.self-convert-tuples-to-table-type
Issue:
https://github.com/tarantool/tarantool/issues/4513

 src/box/lua/net_box.lua       | 10 ++++++++-
 test/app-tap/debug.result     |  8 +++----
 test/box-tap/net.box.test.lua | 39 ++++++++++++++++++++++++++++++++---
 3 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
index b4811edfa..47ac72b80 100644
--- a/src/box/lua/net_box.lua
+++ b/src/box/lua/net_box.lua
@@ -1550,7 +1550,15 @@ local function handle_eval_result(status, ...)
         rollback()
         return box.error(E_PROC_LUA, (...))
     end
-    return ...
+
+    local results = {...}
+    for i = 0, select('#', results) do
+        if type(results[i]) == 'cdata' then
+            results[i] = msgpack.decode(msgpack.encode(results[i]))
+        end
+    end
+    
+    return unpack(results)
 end
 
 this_module.self = {
diff --git a/test/app-tap/debug.result b/test/app-tap/debug.result
index 72934b076..cdc990307 100644
--- a/test/app-tap/debug.result
+++ b/test/app-tap/debug.result
@@ -15,15 +15,15 @@ nil
 Exec: tarantool -e "print(debug.__dir__); os.exit(0)"
 .
 Exec: tarantool -e "print(require('net.box').self:call('debug.sourcefile')); os.exit(0)"
-nil
+
 Exec: tarantool -e "print(require('net.box').self:call('debug.sourcedir')); os.exit(0)"
 .
 Exec: tarantool -e "fn = function() return debug.__file__ end; print(require('net.box').self:call('fn')); os.exit(0)"
-nil
+
 Exec: tarantool -e "fn = function() return debug.__dir__ end; print(require('net.box').self:call('fn')); os.exit(0)"
 .
 Exec: tarantool -e "fn = function() local res = debug.sourcefile(); return res end; print(require('net.box').self:call('fn')); os.exit(0)"
-nil
+
 Exec: tarantool -e "fn = function() local res = debug.sourcedir(); return res end; print(require('net.box').self:call('fn')); os.exit(0)"
 .
 Exec: tarantool -e "print(loadstring('return debug.sourcefile()')()); os.exit(0)"
@@ -52,7 +52,7 @@ debug/test.lua
 Source: print(debug.__dir__)
 debug
 Source: print(require('net.box').self:call('debug.sourcefile'))
-nil
+
 Source: print(require('net.box').self:call('debug.sourcedir'))
 .
 Source: fn = function() return debug.__file__ end; print(require('net.box').self:call('fn'))
diff --git a/test/box-tap/net.box.test.lua b/test/box-tap/net.box.test.lua
index a46f28ad0..fefbe7ff7 100755
--- a/test/box-tap/net.box.test.lua
+++ b/test/box-tap/net.box.test.lua
@@ -7,7 +7,7 @@ local net_box = require('net.box')
 local test_run = require('test_run')
 local inspector = test_run.new()
 
-test:plan(5)
+test:plan(11)
 
 -- create tarantool instance
 test:is(
@@ -27,8 +27,41 @@ test:is(conn.space ~= nil, true, 'space exists')
 -- gh-1814: Segfault if using `net.box` before `box.cfg` start
 test:ok(not pcall(function() conn.space._vspace:insert() end), "error handling")
 
+--
+-- gh-4513 netbox.connect and netbox.self should be interchangeable
+--
+box.cfg{
+    listen = os.getenv('LISTEN')
+}
+
+space = box.schema.space.create('gh4513')
+box.schema.user.grant('guest','read, write, execute','universe')
+idx = box.space.gh4513:create_index('primary')
+box.space.gh4513:insert({1})
+
+local dst = box.cfg.listen
+local t1 = type(net_box.connect(dst):eval("return box.space.gh4513:get({1})"))
+local t2 = type(net_box.self:eval("return box.space.gh4513:get{1}"))
+
+-- connect and self should convert tuples to tables
+test:is(t1, "table", "connect converts to table")
+test:is(t2, "table", "self convert to table")
+
+t1 = type(net_box.connect(dst):eval("return box.error.new(1, 'test error')"))
+t2 = type(net_box.self:eval("return box.error.new(1, 'test error')"))
+
+-- check for converting strings
+test:is(t1, "string", "connect converts to strings")
+test:is(t2, "string", "self converts to strings")
+
+t1 = type(net_box.connect(dst):eval("return box.NULL"))
+t2 = type(net_box.self:eval("return box.NULL"))
+
+-- check for converting cdata
+test:is(t1, "cdata", "connect converts to cdata")
+test:is(t2, "cdata", "self converts to cdata")
+
 -- cleanup
 conn:close()
 inspector:cmd('stop server second with cleanup=1')
-test:check()
-os.exit(0)
+os.exit(test:check() and 0 or 1)
-- 
2.24.0

             reply	other threads:[~2020-01-17 17:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-17 17:08 Maria [this message]
2020-01-20 21:22 ` Vladislav Shpilevoy
2020-01-27 16:13   ` Maria Khaydich
2020-02-26 13:51     ` Igor Munkin
2020-03-03 18:05       ` Maria Khaydich
2020-03-03 22:49         ` Vladislav Shpilevoy
2020-03-06 12:19           ` Maria Khaydich
2020-03-08 22:57             ` Vladislav Shpilevoy
  -- strict thread matches above, loose matches on Subject: below --
2019-12-12 21:28 Maria
2019-12-13 13:53 ` Oleg Babin

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=20200117170801.34975-1-maria.khaydich@tarantool.org \
    --to=maria.khaydich@tarantool.org \
    --cc=imun@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] box: netbox.self and connect should work interchangeably' \
    /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