Make get and call_sync error
Signed-off-by: Rahix <rahix@rahix.de>
This commit is contained in:
parent
4b5fcf3d99
commit
1b73d0d04c
4 changed files with 17 additions and 13 deletions
18
bc.lua
18
bc.lua
|
|
@ -185,19 +185,19 @@ function BaseControl:get(noun, timeout)
|
|||
ty=Message.NounRequest,
|
||||
noun=noun,
|
||||
})
|
||||
local answer, err = self.network:pull(function(remote, msg)
|
||||
local answer = self.network:pull(function(remote, msg)
|
||||
if remote ~= self.remote_nouns[noun] then return false end
|
||||
if msg.ty ~= Message.NounResponse then return false end
|
||||
if msg.noun ~= noun then return false end
|
||||
return true
|
||||
end, timeout)
|
||||
if answer == nil then
|
||||
return nil, err
|
||||
else
|
||||
if answer ~= nil then
|
||||
return answer.value
|
||||
else
|
||||
error("timeout")
|
||||
end
|
||||
else
|
||||
return nil, "noun \""..noun.."\" unknown"
|
||||
return error("unknown")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -247,8 +247,6 @@ function BaseControl:call(verb, ...)
|
|||
verb=verb,
|
||||
param={...},
|
||||
})
|
||||
else
|
||||
error("unknown verb")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -262,7 +260,7 @@ function BaseControl:call_sync(verb, ...)
|
|||
param={...},
|
||||
sync=true,
|
||||
})
|
||||
local answer, err = self.network:pull(function(remote, msg)
|
||||
local answer = self.network:pull(function(remote, msg)
|
||||
if remote ~= self.remote_verbs[verb] then return false end
|
||||
if msg.ty ~= Message.VerbResponse then return false end
|
||||
if msg.verb ~= verb then return false end
|
||||
|
|
@ -271,10 +269,10 @@ function BaseControl:call_sync(verb, ...)
|
|||
if answer ~= nil then
|
||||
return table.unpack(answer.ret)
|
||||
else
|
||||
return nil, err
|
||||
error("timeout")
|
||||
end
|
||||
else
|
||||
error("unknown verb")
|
||||
error("unknown")
|
||||
end
|
||||
end
|
||||
-- }}}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ function test_get_network_robust()
|
|||
)
|
||||
|
||||
assert_equal(123, bc2:get("getrob1"), "wrong value")
|
||||
assert_nil(bc2:get("getrob2"), "found non-exisiting")
|
||||
assert_error_match("unknown", function()
|
||||
bc2:get("getrob2")
|
||||
end)
|
||||
end
|
||||
|
||||
function test_call_sync_network_robust()
|
||||
|
|
|
|||
|
|
@ -68,7 +68,9 @@ function test_get()
|
|||
bc:finalize()
|
||||
|
||||
assert_equal(1234, bc:get("get1"), "wrong value for noun")
|
||||
assert_equal(nil, bc:get("get2"), "got value for non-exisiting noun")
|
||||
assert_error_match("unknown", function()
|
||||
bc:get("get2")
|
||||
end)
|
||||
assert_error_match("not a noun", function()
|
||||
bc:get("get2v")
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ function test_get_network()
|
|||
local bc2 = BaseControl:new()
|
||||
|
||||
assert_equal(123, bc2:get("getnw1"), "wrong value")
|
||||
assert_nil(bc2:get("getnw2"), "found non-exisiting")
|
||||
assert_error_match("unknown", function()
|
||||
bc2:unknown("getnw2")
|
||||
end)
|
||||
end
|
||||
|
||||
function test_call_network()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue