Teste de relatório de jobs terminados ao reconectar.
[SOMA-6857][SOMA-7166][SOMA-6693]
... | ... | @@ -108,69 +108,78 @@ describe("Registering SGA", function () { |
const [exitVal] = await sga.terminated(); | ||
expect(exitVal).toEqual(0); | ||
}); | ||
}); | ||
it("should receive requests to execute and inform its completion", async () => { | ||
const jobBody = utils.fillJobBody(); | ||
const driverMockup = { | ||
execute_command: ` | ||
expect(job.cmd_id == ${JSON.stringify(jobBody.cmd_id)}) | ||
expect(cmd_string == ${JSON.stringify(jobBody.cmd_string)}) | ||
expect(user_token == ${JSON.stringify( | ||
jobBody.parameters.csbase_command_user_token | ||
)}) | ||
expect(not self.jobDataRef) | ||
self.jobDataRef = job.data | ||
job.data.start = now() | ||
return true | ||
`, | ||
is_command_done: ` | ||
expect(self.jobDataRef == job.data) | ||
if not job.data.start or now()-job.data.start < 0.1 then | ||
return false | ||
end | ||
job.data.start = false | ||
return true, 0.07, 0.03, 0.01 | ||
`, | ||
cleanup_job: ` | ||
expect(self.jobDataRef == job.data) | ||
expect(not self.jobCleanup) | ||
self.jobCleanup = true | ||
`, | ||
"actions.status": ` | ||
expect(self.jobDataRef == job.data) | ||
expect(action == "status") | ||
return true, { | ||
someStatus = "some status", | ||
otherStatus = "other status", | ||
anotherStatus = "another status", | ||
nestedStatus = { | ||
someNestedStatus = "some nested status", | ||
otherNestedStatus = "other nested status", | ||
anotherNestedStatus = "another nested status", | ||
} | ||
describe("Mocked SGA", function () { | ||
let config; | ||
let regMockup; | ||
let sga; | ||
const jobBody = utils.fillJobBody(); | ||
const driverMockup = { | ||
execute_command: ` | ||
expect(job.cmd_id == ${JSON.stringify(jobBody.cmd_id)}) | ||
expect(cmd_string == ${JSON.stringify(jobBody.cmd_string)}) | ||
expect(user_token == ${JSON.stringify( | ||
jobBody.parameters.csbase_command_user_token | ||
)}) | ||
expect(not self.jobDataRef) | ||
self.jobDataRef = job.data | ||
job.data.start = now() | ||
return true | ||
`, | ||
is_command_done: ` | ||
expect(self.jobDataRef == job.data) | ||
if not job.data.start or now()-job.data.start < 0.1 then | ||
return false | ||
end | ||
job.data.start = false | ||
return true, 0.07, 0.03, 0.01 | ||
`, | ||
cleanup_job: ` | ||
expect(self.jobDataRef == job.data) | ||
expect(not self.jobCleanup) | ||
self.jobCleanup = true | ||
`, | ||
"actions.status": ` | ||
expect(self.jobDataRef == job.data) | ||
expect(action == "status") | ||
return true, { | ||
someStatus = "some status", | ||
otherStatus = "other status", | ||
anotherStatus = "another status", | ||
nestedStatus = { | ||
someNestedStatus = "some nested status", | ||
otherNestedStatus = "other nested status", | ||
anotherNestedStatus = "another nested status", | ||
} | ||
`, | ||
}; | ||
async function checkStatus(url) { | ||
const statRes = await chakram.get(url); | ||
chakram.expect(statRes).to.have.status(200); | ||
chakram.expect(statRes).to.comprise.of.json({ | ||
someStatus: "some status", | ||
otherStatus: "other status", | ||
anotherStatus: "another status", | ||
nestedStatus: { | ||
someNestedStatus: "some nested status", | ||
otherNestedStatus: "other nested status", | ||
anotherNestedStatus: "another nested status", | ||
}, | ||
}); | ||
} | ||
} | ||
`, | ||
}; | ||
const config = utils.fillSgaConfig(); | ||
const regMockup = new utils.RegistryService(config); | ||
const sga = new utils.SgaDaemon(config, driverMockup); | ||
afterEach(utils.clearAllResources); | ||
beforeEach(() => { | ||
config = utils.fillSgaConfig(); | ||
regMockup = new utils.RegistryService(config); | ||
sga = new utils.SgaDaemon(config, driverMockup); | ||
}); | ||
async function checkStatus(url) { | ||
const statRes = await chakram.get(url); | ||
chakram.expect(statRes).to.have.status(200); | ||
chakram.expect(statRes).to.comprise.of.json({ | ||
someStatus: "some status", | ||
otherStatus: "other status", | ||
anotherStatus: "another status", | ||
nestedStatus: { | ||
someNestedStatus: "some nested status", | ||
otherNestedStatus: "other nested status", | ||
anotherNestedStatus: "another nested status", | ||
}, | ||
}); | ||
} | ||
it("should receive requests to execute and inform its completion", async () => { | ||
spyOn(regMockup, "heartbeat").and.callThrough(); | ||
spyOn(regMockup, "status").and.callThrough(); | ||
... | ... | @@ -198,6 +207,52 @@ describe("Registering SGA", function () { |
await checkStatus(execRes.body.actions.status); | ||
}); | ||
it("should report jobs completed on registration", async () => { | ||
function notFound(req, res) { | ||
res.status(404).end(); | ||
} | ||
await regMockup.start(); | ||
await sga.start(); | ||
const [regReq1] = await events.once(regMockup.events, "register"); | ||
utils.checkRegistration(regReq1, config); | ||
const registerSpy = spyOn(regMockup, "register"); | ||
const heartbeatSpy = spyOn(regMockup, "heartbeat"); | ||
const statusSpy = spyOn(regMockup, "status"); | ||
const completionSpy = spyOn(regMockup, "completion"); | ||
registerSpy.and.callFake(notFound); | ||
|
||
heartbeatSpy.and.callFake(notFound); | ||
statusSpy.and.callFake(notFound); | ||
completionSpy.and.callFake(notFound); | ||
const execRes = await chakram.post(regReq1.body.actions.job, jobBody); | ||
chakram.expect(execRes).to.have.status(201); | ||
await utils.waitMsec(200); // time for job to complete | ||
registerSpy.and.callThrough(); | ||
const [regReq2] = await events.once(regMockup.events, "register"); | ||
utils.checkRegistration(regReq2, config); | ||
heartbeatSpy.and.callThrough(); | ||
statusSpy.and.callThrough(); | ||
completionSpy.and.callThrough(); | ||
expect(regReq2.body.persistent_data.lost).toEqual( | ||
jasmine.objectContaining({}) | ||
); | ||
const retrievedJob = regReq2.body.persistent_data.retrieved[0]; | ||
expect(retrievedJob.cmd_id).toEqual(jobBody.cmd_id); | ||
expect(retrievedJob.actions).toEqual( | ||
jasmine.objectContaining(execRes.body.actions) | ||
); | ||
await checkStatus(execRes.body.actions.status); | ||
}); | ||
}); | ||
describe("Registered SGA", function () { | ||
... | ... |