Tarantool development patches archive
 help / color / mirror / Atom feed
From: Chris Sosnin <k.sosnin@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v3 1/2] test: introduce iproto_request helper function
Date: Wed, 11 Mar 2020 12:13:59 +0300	[thread overview]
Message-ID: <d2dcf742b2c5f36442fed849951010474e45954a.1583917262.git.k.sosnin@tarantool.org> (raw)
In-Reply-To: <cover.1583917262.git.k.sosnin@tarantool.org>

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)

  reply	other threads:[~2020-03-11  9:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11  9:13 [Tarantool-patches] [PATCH v3 0/2] add an empty body to the unprepare response Chris Sosnin
2020-03-11  9:13 ` Chris Sosnin [this message]
2020-03-11  9:14 ` [Tarantool-patches] [PATCH v3 2/2] iproto: " Chris Sosnin
2020-03-15 15:31   ` Vladislav Shpilevoy
2020-03-16  9:02     ` Chris Sosnin
2020-03-16 22:01       ` Vladislav Shpilevoy
2020-03-17 14:15         ` Nikita Pettik

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=d2dcf742b2c5f36442fed849951010474e45954a.1583917262.git.k.sosnin@tarantool.org \
    --to=k.sosnin@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v3 1/2] test: introduce iproto_request helper function' \
    /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