Commit 70c513fe authored by Renato Figueiro Maia's avatar Renato Figueiro Maia
Browse files

Correção para encerrar SGA caso intevalo de heartbeat seja inválido.

[SOMA-5343][SOMA-6857]
parent 7d7cca1a
......@@ -138,19 +138,19 @@ local function startapp(self)
local nodes, n_err = self.driver:get_nodes()
if not nodes then
return nil, "Failed getting node configuration: " .. tostring(n_err)
error("Failed getting node configuration: " .. tostring(n_err))
end
local sga_type = self.config.sga_type or self.driver.type or "machine"
local reg_ok, reg_err = self.client:register(sga_type, nodes, self.server)
if not reg_ok then
return nil, "Failed registering: " .. tostring(reg_err)
error("Failed registering: " .. tostring(reg_err))
end
local function loop_operation(msg, interval, fn)
assert(interval and interval >= 0,
"illegal '" .. msg .. "' interval (got " .. interval .. ")")
"illegal '" .. msg .. "' interval (got " .. tostring(interval) .. ")")
return copas.addthread(function()
while not self.server.down do
if self.client.registered then
......@@ -183,9 +183,15 @@ local function startapp(self)
end
function application.run(self)
copas.addthread(startapp, self)
copas.addthread(function ()
local ok, err = pcall(startapp, self)
if not ok then
io.stderr:write(tostring(err).."\n")
os.exit(1)
end
end)
self.server:start()
return true
io.stderr:write("\27[1;32m".."sgad terminated gracefully.".."\27[0m\n")
end
return application
......@@ -110,12 +110,4 @@ if not app then
os.exit(1)
end
local ok, err = app:run()
if ok then
io.stderr:write("\27[1;32m".."sgad terminated gracefully.".."\27[0m\n")
os.exit(0)
else
io.stderr:write(tostring(err).."\n")
os.exit(1)
end
app:run()
......@@ -4,7 +4,7 @@ const chakram = require("chakram");
const events = require("events");
const utils = require("./utils");
describe("Started SGA", function () {
describe("Registering SGA", function () {
afterEach(utils.clearAllResources);
it("should terminate on shutdown after registration", async () => {
......@@ -25,6 +25,21 @@ describe("Started SGA", function () {
expect(exitVal).toEqual(0);
});
it("should exit with code 1 on invalid heartbeat interval", async () => {
const config = utils.fillSgaConfig();
const regMockup = new utils.RegistryService(config, -1);
const sga = new utils.SgaDaemon(config);
await regMockup.start();
await sga.start();
const [regReq] = await events.once(regMockup.events, "register");
utils.checkRegistration(regReq, config);
const [exitVal] = await sga.terminated();
expect(exitVal).toEqual(1);
});
it("should retry to register when server is down", async () => {
const regMockupPort = 55555;
const regMockupBaseUri = `http://localhost:${regMockupPort}`;
......
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