[Tarantool-patches] [PATCH v4 11/12] test: move txn_proxy.lua to box/lua
Aleksandr Lyapunov
alyapunov at tarantool.org
Tue Sep 8 13:22:11 MSK 2020
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
More information about the Tarantool-patches
mailing list