Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-abramovich-payu-gpo committed Oct 1, 2023
1 parent 494cca1 commit 528364e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/jobs/models/jobExperimentsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 9 additions & 2 deletions tests/unit-tests/jobs/models/jobExperimentsHandler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Job experiments handler tests', function () {
let experimentsManagerGetStub;
let experimentsManagerRunJobStub;
let sandbox;
let clock;

before(() => {
sandbox = sinon.sandbox.create();
Expand All @@ -38,6 +39,13 @@ describe('Job experiments handler tests', function () {
sandbox.reset();
});

afterEach(async () => {
if (clock){
clock.restore();
clock = undefined;
}
});

after(() => {
sandbox.restore();
});
Expand All @@ -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);
Expand All @@ -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 () => {
Expand Down

0 comments on commit 528364e

Please sign in to comment.