Skip to content
Snippets Groups Projects
Commit 29542070 authored by Nikolay Shirokovskiy's avatar Nikolay Shirokovskiy Committed by Vladimir Davydov
Browse files

console: use streams in binary console

Now we can make interactive transactions like in case of
local or txt remote consoles if peer supports streams.

Closes #7413

NO_DOC=minor change
parent b013233f
No related branches found
No related tags found
No related merge requests found
## feature/core
* Supported interactive transactions for remote binary console (gh-7413).
...@@ -578,7 +578,7 @@ end ...@@ -578,7 +578,7 @@ end
-- --
local function remote_eval(self, line) local function remote_eval(self, line)
if line and self.remote.state == 'active' then if line and self.remote.state == 'active' then
local ok, res = pcall(self.remote.eval, self.remote, line) local ok, res = pcall(self.remote.console_eval, line)
if self.remote.state == 'active' then if self.remote.state == 'active' then
return ok and res or format(false, res) return ok and res or format(false, res)
end end
...@@ -586,6 +586,7 @@ local function remote_eval(self, line) ...@@ -586,6 +586,7 @@ local function remote_eval(self, line)
local err = self.remote.error local err = self.remote.error
self.remote:close() self.remote:close()
self.remote = nil self.remote = nil
self.console_eval = nil
self.eval = nil self.eval = nil
self.prompt = nil self.prompt = nil
self.completion = nil self.completion = nil
...@@ -834,18 +835,26 @@ local function connect(uri, opts) ...@@ -834,18 +835,26 @@ local function connect(uri, opts)
log.verbose(err) log.verbose(err)
box.error(box.error.NO_CONNECTION) box.error(box.error.NO_CONNECTION)
end end
remote.console_eval = function(line)
return remote:eval(line)
end
else else
if not remote.host then if not remote.host then
remote.host = 'localhost' remote.host = 'localhost'
end end
local old_eval = remote.eval local eval_obj
remote.eval = function(con, line) if remote.peer_protocol_features.streams then
return old_eval(con, 'return require("console").eval(...)', {line}) eval_obj = remote:new_stream()
else
eval_obj = remote
end
remote.console_eval = function(line)
return eval_obj:eval('return require("console").eval(...)', {line})
end end
end end
-- check connection && permissions -- check connection && permissions
local ok, res = pcall(remote.eval, remote, 'return true') local ok, res = pcall(remote.console_eval, 'return true')
if not ok then if not ok then
remote:close() remote:close()
pcall(self.on_client_disconnect, self) pcall(self.on_client_disconnect, self)
...@@ -860,7 +869,7 @@ local function connect(uri, opts) ...@@ -860,7 +869,7 @@ local function connect(uri, opts)
local c = string.format( local c = string.format(
'return require("console").completion_handler(%q, %d, %d)', 'return require("console").completion_handler(%q, %d, %d)',
str, pos1, pos2) str, pos1, pos2)
return yaml.decode(remote:eval(c))[1] return yaml.decode(remote.console_eval(c))[1]
end end
log.info("connected to %s:%s", self.remote.host, self.remote.port) log.info("connected to %s:%s", self.remote.host, self.remote.port)
return true return true
......
...@@ -3,6 +3,7 @@ local console = require('console') ...@@ -3,6 +3,7 @@ local console = require('console')
local fiber = require('fiber') local fiber = require('fiber')
local fio = require('fio') local fio = require('fio')
local string = require('string') local string = require('string')
local netbox = require('net.box')
local t = require('luatest') local t = require('luatest')
local function configure_box() local function configure_box()
...@@ -158,7 +159,6 @@ local false_output = [[ ...@@ -158,7 +159,6 @@ local false_output = [[
]] ]]
g.test_begin_in_expr_without_error = function(cg) g.test_begin_in_expr_without_error = function(cg)
t.xfail_if(cg.params.name == "remote_bin")
local console = cg.console local console = cg.console
console:send('box.begin()') console:send('box.begin()')
t.assert_equals(console:send('box.is_in_txn()'), true_output) t.assert_equals(console:send('box.is_in_txn()'), true_output)
...@@ -176,9 +176,52 @@ g.test_begin_in_expr_with_error = function(cg) ...@@ -176,9 +176,52 @@ g.test_begin_in_expr_with_error = function(cg)
end end
g.test_error_in_different_expr = function(cg) g.test_error_in_different_expr = function(cg)
t.xfail_if(cg.params.name == "remote_bin")
local console = cg.console local console = cg.console
console:send('box.begin()') console:send('box.begin()')
console:send('error("test error")') console:send('error("test error")')
t.assert_equals(console:send('box.is_in_txn()'), true_output) t.assert_equals(console:send('box.is_in_txn()'), true_output)
end end
local gb = t.group('gh-7288-bin-backcompat')
gb.before_all(function()
gb.save = netbox.connect
netbox.connect = function(...)
local remote = gb.save(...)
remote.peer_protocol_features.streams = false
return remote
end
gb.console = TestConsole:new(flavours.remote_bin)
gb.console:start()
end)
gb.after_all(function()
gb.console:stop()
gb.console = nil
netbox.connect = gb.save
end)
gb.before_each(function()
gb.console:connect()
end)
gb.after_each(function()
gb.console:disconnect()
end)
gb.test_remote_bin_no_streams_works = function(cg)
local console = cg.console
-- first check we have backcompat mode without streams
local expected = [[
---
- error: Transaction is active at return from function
...
]]
t.assert_equals(console:send('box.begin()'), expected)
local expected = [[
---
- 4
...
]]
t.assert_equals(console:send('2 + 2'), expected)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment