Make get and call_sync error

Signed-off-by: Rahix <rahix@rahix.de>
dev
rahix 7 years ago
parent 4b5fcf3d99
commit 1b73d0d04c

@ -185,19 +185,19 @@ function BaseControl:get(noun, timeout)
ty=Message.NounRequest, ty=Message.NounRequest,
noun=noun, 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 remote ~= self.remote_nouns[noun] then return false end
if msg.ty ~= Message.NounResponse then return false end if msg.ty ~= Message.NounResponse then return false end
if msg.noun ~= noun then return false end if msg.noun ~= noun then return false end
return true return true
end, timeout) end, timeout)
if answer == nil then if answer ~= nil then
return nil, err
else
return answer.value return answer.value
else
error("timeout")
end end
else else
return nil, "noun \""..noun.."\" unknown" return error("unknown")
end end
end end
@ -247,8 +247,6 @@ function BaseControl:call(verb, ...)
verb=verb, verb=verb,
param={...}, param={...},
}) })
else
error("unknown verb")
end end
end end
@ -262,7 +260,7 @@ function BaseControl:call_sync(verb, ...)
param={...}, param={...},
sync=true, 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 remote ~= self.remote_verbs[verb] then return false end
if msg.ty ~= Message.VerbResponse then return false end if msg.ty ~= Message.VerbResponse then return false end
if msg.verb ~= verb 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 if answer ~= nil then
return table.unpack(answer.ret) return table.unpack(answer.ret)
else else
return nil, err error("timeout")
end end
else else
error("unknown verb") error("unknown")
end end
end end
-- }}} -- }}}

@ -26,7 +26,9 @@ function test_get_network_robust()
) )
assert_equal(123, bc2:get("getrob1"), "wrong value") 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 end
function test_call_sync_network_robust() function test_call_sync_network_robust()

@ -68,7 +68,9 @@ function test_get()
bc:finalize() bc:finalize()
assert_equal(1234, bc:get("get1"), "wrong value for noun") 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() assert_error_match("not a noun", function()
bc:get("get2v") bc:get("get2v")
end) end)

@ -28,7 +28,9 @@ function test_get_network()
local bc2 = BaseControl:new() local bc2 = BaseControl:new()
assert_equal(123, bc2:get("getnw1"), "wrong value") 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 end
function test_call_network() function test_call_network()

Loading…
Cancel
Save