Commit f4bb05fd authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-2476] [Lua] Assistente não pode aceitar tempo de espera entre tentativas igual a ZERO

- Correção para que operações do assistente com retentativas indeterminadas encerrem caso a operação 'shutdown' do assistente seja chamada.


git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/branches/02_00_00@155758 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 89af9974
...@@ -158,7 +158,7 @@ function Assistant:findServices(properties, retries, interval) ...@@ -158,7 +158,7 @@ function Assistant:findServices(properties, retries, interval)
ok, result = pcall(conn.findServices, conn, properties) ok, result = pcall(conn.findServices, conn, properties)
if not ok then if not ok then
local newinterval = callobserver(self, "Find", result) local newinterval = callobserver(self, "Find", result)
if retries == 0 then if retries == 0 or self.canceled then
return {} return {}
end end
retries = retries-1 retries = retries-1
...@@ -176,7 +176,7 @@ do ...@@ -176,7 +176,7 @@ do
ok, result = pcall(method, object, ...) ok, result = pcall(method, object, ...)
if not ok then if not ok then
local newinterval = callobserver(self, event, ...) local newinterval = callobserver(self, event, ...)
if retries == 0 then if retries == 0 or self.canceled then
return error(result) -- TODO: is this the correct thing to do? return error(result) -- TODO: is this the correct thing to do?
end end
retries = retries-1 retries = retries-1
......
...@@ -9,9 +9,9 @@ local coroutine = require "coroutine" ...@@ -9,9 +9,9 @@ local coroutine = require "coroutine"
local string = require "string" local string = require "string"
local io = require "io" local io = require "io"
local uuid = require "uuid" local uuid = require "uuid"
local socket = require "socket.core"
local Matcher = require "loop.debug.Matcher" local Matcher = require "loop.debug.Matcher"
local Viewer = require "loop.debug.Viewer" local Viewer = require "loop.debug.Viewer"
local Wrapper = require "loop.object.Wrapper"
local table = require "loop.table" local table = require "loop.table"
local giop = require "oil.corba.giop" local giop = require "oil.corba.giop"
local cothread = require "cothread" local cothread = require "cothread"
...@@ -130,6 +130,12 @@ do ...@@ -130,6 +130,12 @@ do
[thread] = "bad field 'busport' to 'create' %(expected number|string, got thread%)$", [thread] = "bad field 'busport' to 'create' %(expected number|string, got thread%)$",
[userdata] = "bad field 'busport' to 'create' %(expected number|string, got userdata%)$", [userdata] = "bad field 'busport' to 'create' %(expected number|string, got userdata%)$",
}, },
interval = {
[-1] = "interval too small, minimum is 1 second",
[0] = "interval too small, minimum is 1 second",
[0.1] = "interval too small, minimum is 1 second",
[0.9999] = "interval too small, minimum is 1 second",
},
} }
local ValidParams = { local ValidParams = {
orb = orb, orb = orb,
...@@ -155,28 +161,32 @@ log:TEST(true, "Illegal Login Parameters") ...@@ -155,28 +161,32 @@ log:TEST(true, "Illegal Login Parameters")
local function assertLoginFailure(params, expected) local function assertLoginFailure(params, expected)
local theAssistant local theAssistant
local complete local last, notified
local observer = { local observer = {
onLoginFailure = function (self, anAssistant, ex) onLoginFailure = function (self, anAssistant, ex)
local now = socket.gettime()
if type(expected) == "string" then if type(expected) == "string" then
assert(string.find(ex, expected, 1+#ex-#expected, true)) assert(string.find(ex, expected, 1+#ex-#expected, true))
else else
assert(Matcher{isomorphic=false,metatable=false}:match(expected, ex)) assert(Matcher{isomorphic=false,metatable=false}:match(expected, ex))
end end
if theAssistant ~= nil then if last ~= nil then
assert(now - last > 1)
assert(anAssistant == theAssistant) assert(anAssistant == theAssistant)
anAssistant:shutdown() anAssistant:shutdown()
complete = true notified = true
end end
last = now
end end
} }
params.interval = 1
params.observer = observer params.observer = observer
theAssistant = assistant.create(params) theAssistant = assistant.create(params)
for i = 1, 3 do for i = 1, 3 do
if complete then break end if notified then break end
cothread.delay(theAssistant.interval) cothread.delay(theAssistant.interval)
end end
assert(complete) assert(notified)
end end
do do
...@@ -270,12 +280,12 @@ local invalidate, sharedauth, shutdown, leasetime do ...@@ -270,12 +280,12 @@ local invalidate, sharedauth, shutdown, leasetime do
end end
end end
local events = table.memoize(function () return 0 end) --local events = table.memoize(function () return 0 end)
local observer = table.memoize(function (event) --local observer = table.memoize(function (event)
return function (...) -- return function (...)
events[event] = events[event] + 1 -- events[event] = events[event] + 1
end -- end
end) --end)
do do
local function testlogin(params) local function testlogin(params)
...@@ -326,8 +336,9 @@ do ...@@ -326,8 +336,9 @@ do
log:TEST(false) log:TEST(false)
end end
do log:TEST "access denied on relogin" for interval = 1, 3 do
local ready, notified log:TEST("access denied on relogin with interval of ",interval," seconds")
local last, notified
local entity, secret = user, password local entity, secret = user, password
local a local a
a = assistant.create{ a = assistant.create{
...@@ -335,28 +346,27 @@ do log:TEST "access denied on relogin" ...@@ -335,28 +346,27 @@ do log:TEST "access denied on relogin"
bushost = bushost, bushost = bushost,
busport = busport, busport = busport,
loginargs = function () return "Password", entity, secret end, loginargs = function () return "Password", entity, secret end,
observer = Wrapper{ interval = interval,
__object = observer, observer = {
onLoginFailure = function (self, assist, except) onLoginFailure = function (self, assist, except)
local now = socket.gettime()
assert(except._repid == idl.types.services.access_control.AccessDenied) assert(except._repid == idl.types.services.access_control.AccessDenied)
if ready then if last ~= nil then
assert(now - last > interval)
assert(assist == a) assert(assist == a)
assist:shutdown() assist:shutdown()
notified = true notified = true
end end
return self.__object:onLoginFailure(assist, except) last = now
end, end,
}, },
} }
assert(#(a:findServices({}, -1)) == 0) -- wait until login assert(#(a:findServices{}) == 0) -- wait until login
assertlogged(a) assertlogged(a)
secret = "WrongPassword" secret = "WrongPassword"
invalidate(OpenBusContext:getCurrentConnection().login.id) invalidate(OpenBusContext:getCurrentConnection().login.id)
sleep(leasetime+a.interval) assert(#(a:findServices{}) == 0) -- wait until relogin
ready = true
sleep(a.interval)
assert(notified) assert(notified)
assert(events.onLoginFailure < 5)
end end
orb:shutdown() orb:shutdown()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment