From 528364e04767c591215ff71aa5e6f4611e13e7d5 Mon Sep 17 00:00:00 2001 From: Guy Abramovich Date: Sun, 1 Oct 2023 13:34:19 +0300 Subject: [PATCH] fix bugs --- src/jobs/models/jobExperimentsHandler.js | 6 +++--- .../jobs/models/jobExperimentsHandler-test.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/jobs/models/jobExperimentsHandler.js b/src/jobs/models/jobExperimentsHandler.js index 65d87b2d..9f29c912 100644 --- a/src/jobs/models/jobExperimentsHandler.js +++ b/src/jobs/models/jobExperimentsHandler.js @@ -34,14 +34,14 @@ async function setSingleJobExperiment(experimentRequest, chaoExperimentsFromDb, await chaosExperimentsManager.insertChaosJobExperiment(jobExperimentId, jobId, experiment.id, startTime, endTime); const kubeObject = experiment.kubeObject; kubeObject.metadata.name = kubeObject.metadata.name.concat(`-${jobExperimentId}`); - scheduleChaosExperiment(kubeObject, jobId, jobExperimentId, experimentRequest.start_after); + scheduleChaosExperiment(kubeObject, jobExperimentId, experimentRequest.start_after); } catch (error){ logger.error(error, `error while setting chaos experiment ${experimentRequest.experiment_id} for job ${jobId}`); } } -function scheduleChaosExperiment(kubeObject, jobId, jobExperimentId, startAfter) { - const timeout = setTimeout(() => chaosExperimentsManager.runChaosExperiment(kubeObject, jobId, jobExperimentId), startAfter); +function scheduleChaosExperiment(kubeObject, jobExperimentId, startAfter) { + const timeout = setTimeout(() => chaosExperimentsManager.runChaosExperiment(kubeObject, jobExperimentId), startAfter); jobExperimentsIdToTimeout.set(jobExperimentId, timeout); } diff --git a/tests/unit-tests/jobs/models/jobExperimentsHandler-test.js b/tests/unit-tests/jobs/models/jobExperimentsHandler-test.js index d7ed5daa..47a5b239 100644 --- a/tests/unit-tests/jobs/models/jobExperimentsHandler-test.js +++ b/tests/unit-tests/jobs/models/jobExperimentsHandler-test.js @@ -27,6 +27,7 @@ describe('Job experiments handler tests', function () { let experimentsManagerGetStub; let experimentsManagerRunJobStub; let sandbox; + let clock; before(() => { sandbox = sinon.sandbox.create(); @@ -38,6 +39,13 @@ describe('Job experiments handler tests', function () { sandbox.reset(); }); + afterEach(async () => { + if (clock){ + clock.restore(); + clock = undefined; + } + }); + after(() => { sandbox.restore(); }); @@ -60,7 +68,7 @@ describe('Job experiments handler tests', function () { } ]; const jobId = uuid(); - const clock = sinon.useFakeTimers(); + clock = sinon.useFakeTimers(); clock.tick(1000); await jobExperimentHandler.setChaosExperimentsIfExist(jobId, jobExperiments); clock.tick(3000); @@ -74,7 +82,6 @@ describe('Job experiments handler tests', function () { experimentsManagerInsertStub.args[1][1].should.eql(jobId); experimentsManagerInsertStub.args[1][2].should.eql(secondExperiment.id); (experimentsManagerInsertStub.args[1][3] - experimentsManagerInsertStub.args[0][3]).should.eql(1000); - clock.restore(); }); it('set chaos experiments with same experiment in different times', async () => {