From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id C70A9446443 for ; Tue, 8 Sep 2020 13:22:21 +0300 (MSK) Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1kFalZ-0006tc-CF for tarantool-patches@dev.tarantool.org; Tue, 08 Sep 2020 13:22:21 +0300 From: Aleksandr Lyapunov Date: Tue, 8 Sep 2020 13:22:11 +0300 Message-Id: <1599560532-27089-12-git-send-email-alyapunov@tarantool.org> In-Reply-To: <1599560532-27089-1-git-send-email-alyapunov@tarantool.org> References: <1599560532-27089-1-git-send-email-alyapunov@tarantool.org> Subject: [Tarantool-patches] [PATCH v4 11/12] test: move txn_proxy.lua to box/lua List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org txn_proxy is a special utility for transaction tests. Formerly it was used only for vinyl tests and thus was placed in vinyl folder. Now the time has come to test memtx transactions and the utility must be placed amongst other utils - in box/lua. Needed for #4897 --- test/box/lua/txn_proxy.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++ test/vinyl/suite.ini | 2 +- test/vinyl/txn_proxy.lua | 54 ---------------------------------------------- 3 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 test/box/lua/txn_proxy.lua delete mode 100644 test/vinyl/txn_proxy.lua diff --git a/test/box/lua/txn_proxy.lua b/test/box/lua/txn_proxy.lua new file mode 100644 index 0000000..7a4d0b8 --- /dev/null +++ b/test/box/lua/txn_proxy.lua @@ -0,0 +1,54 @@ +-- A fiber can't use multiple transactions simultaneously; +-- i.e. [fiber] --? [transaction] in UML parlor. +-- +-- This module provides a simple transaction proxy facility +-- to control multiple transactions at once. A proxy executes +-- statements in a worker fiber in order to overcome +-- "one transaction per fiber" limitation. +-- +-- Ex: +-- proxy = require('txn_proxy').new() +-- proxy:begin() +-- proxy('box.space.test:replace{1, 42}') +-- proxy:commit() -- or proxy:rollback() + +local ffi = require('ffi') +local yaml = require('yaml') +local fiber = require('fiber') +local console = require('console') + +local array_mt = { __serialize = 'array' } + +local mt = { + __call = function(self, code_str) + self.c1:put(code_str) + local res = yaml.decode(self.c2:get()) + return type(res) == 'table' and setmetatable(res, array_mt) or res + end, + __index = { + begin = function(self) return self('box.begin()') end, + commit = function(self) return self('box.commit()') end, + rollback = function(self) return self('box.rollback()') end, + close = function(self) self.c1:close(); self.c2:close() end + } +} + +local function fiber_main(c1, c2) + local code_str = c1:get() + if code_str then + c2:put(console.eval(code_str)) + return fiber_main(c1, c2) -- tail call + end +end + +local function new_txn_proxy() + local c1, c2 = fiber.channel(), fiber.channel() + local function on_gc() c1:close(); c2:close() end + fiber.create(fiber_main, c1, c2) + return setmetatable({ + c1 = c1, c2 = c2, + __gc = ffi.gc(ffi.new('char[1]'), on_gc) + }, mt) +end + +return { new = new_txn_proxy } diff --git a/test/vinyl/suite.ini b/test/vinyl/suite.ini index 3e11b08..c6cb89a 100644 --- a/test/vinyl/suite.ini +++ b/test/vinyl/suite.ini @@ -4,7 +4,7 @@ description = vinyl integration tests script = vinyl.lua release_disabled = errinj.test.lua errinj_ddl.test.lua errinj_gc.test.lua errinj_stat.test.lua errinj_tx.test.lua errinj_vylog.test.lua partial_dump.test.lua quota_timeout.test.lua recovery_quota.test.lua replica_rejoin.test.lua gh-4864-stmt-alloc-fail-compact.test.lua gh-4805-open-run-err-recovery.test.lua gh-4821-ddl-during-throttled-dump.test.lua gh-3395-read-prepared-uncommitted.test.lua config = suite.cfg -lua_libs = suite.lua stress.lua large.lua txn_proxy.lua ../box/lua/utils.lua +lua_libs = suite.lua stress.lua large.lua ../box/lua/txn_proxy.lua ../box/lua/utils.lua use_unix_sockets = True use_unix_sockets_iproto = True long_run = stress.test.lua large.test.lua write_iterator_rand.test.lua dump_stress.test.lua select_consistency.test.lua throttle.test.lua diff --git a/test/vinyl/txn_proxy.lua b/test/vinyl/txn_proxy.lua deleted file mode 100644 index 7a4d0b8..0000000 --- a/test/vinyl/txn_proxy.lua +++ /dev/null @@ -1,54 +0,0 @@ --- A fiber can't use multiple transactions simultaneously; --- i.e. [fiber] --? [transaction] in UML parlor. --- --- This module provides a simple transaction proxy facility --- to control multiple transactions at once. A proxy executes --- statements in a worker fiber in order to overcome --- "one transaction per fiber" limitation. --- --- Ex: --- proxy = require('txn_proxy').new() --- proxy:begin() --- proxy('box.space.test:replace{1, 42}') --- proxy:commit() -- or proxy:rollback() - -local ffi = require('ffi') -local yaml = require('yaml') -local fiber = require('fiber') -local console = require('console') - -local array_mt = { __serialize = 'array' } - -local mt = { - __call = function(self, code_str) - self.c1:put(code_str) - local res = yaml.decode(self.c2:get()) - return type(res) == 'table' and setmetatable(res, array_mt) or res - end, - __index = { - begin = function(self) return self('box.begin()') end, - commit = function(self) return self('box.commit()') end, - rollback = function(self) return self('box.rollback()') end, - close = function(self) self.c1:close(); self.c2:close() end - } -} - -local function fiber_main(c1, c2) - local code_str = c1:get() - if code_str then - c2:put(console.eval(code_str)) - return fiber_main(c1, c2) -- tail call - end -end - -local function new_txn_proxy() - local c1, c2 = fiber.channel(), fiber.channel() - local function on_gc() c1:close(); c2:close() end - fiber.create(fiber_main, c1, c2) - return setmetatable({ - c1 = c1, c2 = c2, - __gc = ffi.gc(ffi.new('char[1]'), on_gc) - }, mt) -end - -return { new = new_txn_proxy } -- 2.7.4