[Tarantool-patches] [PATCH 02/16] test: don't use IBUF_SHARED in the tests

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sat Mar 20 03:42:39 MSK 2021


In msgpack test it is used only to check that 'struct ibuf *' can
be passed to encode() functions. But soon IBUF_SHARED will be
deleted, and its alternative won't be yield-tolerant. This means
it can't be used in this test. There are yields between the buffer
usages.

In varbinary test it is used in a too complicated way to be able
to put it back normally. And otherwise its usage does not make
much sense - without put() it is going to be created from the
scratch on non-first usage until a yield.

In the module_api test it is used to check if some function works
with 'struct ibuf *'. Can be done without IBUF_SHARED.

Part of #5632
---
 test/app-tap/module_api.test.lua | 4 +++-
 test/app/msgpack.result          | 7 +++++--
 test/app/msgpack.test.lua        | 5 +++--
 test/box/varbinary_type.result   | 3 +--
 test/box/varbinary_type.test.lua | 3 +--
 5 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/test/app-tap/module_api.test.lua b/test/app-tap/module_api.test.lua
index c43d8eacd..28e33a02d 100755
--- a/test/app-tap/module_api.test.lua
+++ b/test/app-tap/module_api.test.lua
@@ -1,5 +1,6 @@
 #!/usr/bin/env tarantool
 
+local ffi = require('ffi')
 local fio = require('fio')
 
 box.cfg{log = "tarantool.log"}
@@ -45,6 +46,7 @@ local function test_buffers(test, module)
     local bufalloc = buffer.static_alloc("char", 128)
     local ibuf = buffer.ibuf()
     local pbuf = ibuf:alloc(128)
+    local ibuf_ptr = ffi.cast('struct ibuf *', ibuf)
 
     test:ok(not module.toibuf(nil), 'toibuf of nil')
     test:ok(not module.toibuf({}), 'toibuf of {}')
@@ -52,7 +54,7 @@ local function test_buffers(test, module)
     test:ok(not module.toibuf(box.NULL), 'toibuf of box.NULL')
     test:ok(not module.toibuf(buffer.reg1), 'toibuf of reg1')
     test:ok(not module.toibuf(bufalloc), 'toibuf of allocated buffer')
-    test:ok(module.toibuf(buffer.IBUF_SHARED), "toibuf of ibuf*")
+    test:ok(module.toibuf(ibuf_ptr), "toibuf of ibuf*")
     test:ok(module.toibuf(ibuf), 'toibuf of ibuf')
     test:ok(not module.toibuf(pbuf), 'toibuf of pointer to ibuf data')
 end
diff --git a/test/app/msgpack.result b/test/app/msgpack.result
index ddf06fc9d..faee66029 100644
--- a/test/app/msgpack.result
+++ b/test/app/msgpack.result
@@ -206,10 +206,10 @@ msgpack.decode(buf.rpos, buf:size() - 1)
 - error: 'msgpack.decode: invalid MsgPack'
 ...
 -- Provide a buffer. Try both 'struct ibuf' and 'struct ibuf *'.
-buf = buffer.IBUF_SHARED
+buf_storage = buffer.ibuf()
 ---
 ...
-buf:reset()
+buf = ffi.cast('struct ibuf *', buf_storage)
 ---
 ...
 size = msgpack.encode({a = 1, b = 2}, buf)
@@ -219,6 +219,9 @@ size = msgpack.encode({a = 1, b = 2}, buf)
 ---
 - {'a': 1, 'b': 2}
 ...
+buf_storage = nil
+---
+...
 buf = buffer.ibuf()
 ---
 ...
diff --git a/test/app/msgpack.test.lua b/test/app/msgpack.test.lua
index 17e05df5c..f5299f550 100644
--- a/test/app/msgpack.test.lua
+++ b/test/app/msgpack.test.lua
@@ -65,10 +65,11 @@ msgpack.encode({1, 2, 3}, buf)
 msgpack.decode(buf.rpos, buf:size() - 1)
 
 -- Provide a buffer. Try both 'struct ibuf' and 'struct ibuf *'.
-buf = buffer.IBUF_SHARED
-buf:reset()
+buf_storage = buffer.ibuf()
+buf = ffi.cast('struct ibuf *', buf_storage)
 size = msgpack.encode({a = 1, b = 2}, buf)
 (msgpack.decode(buf.rpos, size))
+buf_storage = nil
 buf = buffer.ibuf()
 size = msgpack.encode({c = 3, d = 4}, buf)
 (msgpack.decode(buf.rpos, size))
diff --git a/test/box/varbinary_type.result b/test/box/varbinary_type.result
index 9620ee39e..5aa2996df 100644
--- a/test/box/varbinary_type.result
+++ b/test/box/varbinary_type.result
@@ -40,8 +40,7 @@ test_run:cmd("setopt delimiter ';'")
 - true
 ...
 function encode_bin(bytes)
-    local tmpbuf = buffer.IBUF_SHARED
-    tmpbuf:reset()
+    local tmpbuf = buffer.ibuf()
     local p = tmpbuf:alloc(3 + #bytes)
     p[0] = 0x91
     p[1] = 0xC4
diff --git a/test/box/varbinary_type.test.lua b/test/box/varbinary_type.test.lua
index 3c6b66246..7b9a1e721 100644
--- a/test/box/varbinary_type.test.lua
+++ b/test/box/varbinary_type.test.lua
@@ -16,8 +16,7 @@ ffi = require('ffi')
 
 test_run:cmd("setopt delimiter ';'")
 function encode_bin(bytes)
-    local tmpbuf = buffer.IBUF_SHARED
-    tmpbuf:reset()
+    local tmpbuf = buffer.ibuf()
     local p = tmpbuf:alloc(3 + #bytes)
     p[0] = 0x91
     p[1] = 0xC4
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list