Implement call_sync

Signed-off-by: Rahix <rahix@rahix.de>
This commit is contained in:
rahix 2019-04-15 21:21:43 +02:00
parent e4f19c3e20
commit 888ad288af
2 changed files with 61 additions and 1 deletions

View file

@ -75,3 +75,29 @@ function test_call_network()
assert_equal(4321, tmp, "call incomplete")
assert_equal(1, n, "call not correct")
end
function test_call_sync()
local bc1 = BaseControl:new()
local n = 0
bc1:register("sync1", function(p1, p2)
assert_equal(p2, 12)
n = n + 1
return p1 + 10, "hello"
end)
bc1:finalize()
-- Test locally
assert_nil(bc1:call("sync1", 20, 12), "call not nil")
local ret, val = bc1:call_sync("sync1", 30, 12)
assert_equal(40, ret, "local sync not correct")
assert_equal("hello", val, "local sync not multiple")
assert_equal(2, n, "wrong invokation number")
-- Test remote
local bc2 = BaseControl:new()
assert_nil(bc2:call("sync1", 20, 12), "call not nil")
local ret, val = bc2:call_sync("sync1", 30, 12)
assert_equal(40, ret, "local sync not correct")
assert_equal("hello", val, "local sync not multiple")
assert_equal(4, n, "wrong invokation number")
end