Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csbase-dev
sgarest-daemon
Commits
70c513fe
Commit
70c513fe
authored
Dec 21, 2020
by
Renato Figueiro Maia
Browse files
Correção para encerrar SGA caso intevalo de heartbeat seja inválido.
[SOMA-5343][SOMA-6857]
parent
7d7cca1a
Changes
3
Hide whitespace changes
Inline
Side-by-side
sga/application.lua
View file @
70c513fe
...
...
@@ -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
sgad.lua
View file @
70c513fe
...
...
@@ -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
()
test/spec/rest_spec.js
View file @
70c513fe
...
...
@@ -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
}
`
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment