[Tarantool-patches] [PATCH v3 1/2] test: introduce iproto_request helper function

Chris Sosnin k.sosnin at tarantool.org
Wed Mar 11 12:13:59 MSK 2020


It is needed for performing iproto tests in Lua.

Needed for #4769
---
 test/box/box.lua | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/test/box/box.lua b/test/box/box.lua
index 2a8e0e4fa..6fad07015 100644
--- a/test/box/box.lua
+++ b/test/box/box.lua
@@ -1,6 +1,8 @@
 #!/usr/bin/env tarantool
 os = require('os')
 
+local msgpack = require('msgpack')
+
 box.cfg{
     listen              = os.getenv("LISTEN"),
     memtx_memory        = 107374182,
@@ -38,4 +40,22 @@ function sorted(data)
     return data
 end
 
-_G.protected_globals = {'cfg_filter', 'sorted'}
+function iproto_request(socket, query_header, query_body)
+    local header = msgpack.encode(query_header)
+    local body = msgpack.encode(query_body)
+    local size = msgpack.encode(header:len() + body:len())
+    assert(socket:write(size .. header .. body) ~= nil,
+           'Failed to send request')
+    size = socket:read(5)
+    assert(size ~= nil, 'Failed to read response')
+    size = msgpack.decode(size)
+    local response = socket:read(size)
+    local header, header_len = msgpack.decode(response)
+    body = msgpack.decode(response:sub(header_len))
+    return {
+        ['header'] = header,
+        ['body'] = body,
+    }
+end
+
+_G.protected_globals = {'cfg_filter', 'sorted', 'iproto_request'}
-- 
2.21.1 (Apple Git-122.3)



More information about the Tarantool-patches mailing list