diff --git a/lib/step/func.js b/lib/step/func.js index 2007daa54..f1eca4c2b 100644 --- a/lib/step/func.js +++ b/lib/step/func.js @@ -21,7 +21,7 @@ class FuncStep extends BaseStep { // we wrap that function to track time and status // and disable it in dry run mode this.args = Array.prototype.slice.call(arguments) - this.startTime = +Date.now() + if (!this.startTime) this.startTime = +Date.now() if (store.dryRun) { this.setStatus('success') diff --git a/lib/step/helper.js b/lib/step/helper.js index a87148ac2..07f763ef1 100644 --- a/lib/step/helper.js +++ b/lib/step/helper.js @@ -16,7 +16,7 @@ class HelperStep extends Step { */ run() { this.args = Array.prototype.slice.call(arguments) - this.startTime = +Date.now() + if (!this.startTime) this.startTime = +Date.now() if (store.dryRun) { this.setStatus('success') diff --git a/test/unit/actor_test.js b/test/unit/actor_test.js index 9ab96c5d6..76e8d17b2 100644 --- a/test/unit/actor_test.js +++ b/test/unit/actor_test.js @@ -163,6 +163,16 @@ describe('Actor', () => { return I.failAfter(2) }) + it('should measure duration of a retried step from its first attempt', () => { + recorder.start() + let duration + event.dispatcher.addListener(event.step.finished, step => (duration = step.duration)) + + return I.failAfter(2, step.retry({ retries: 2, minTimeout: 100, factor: 1 })).then(() => { + expect(duration).toBeGreaterThanOrEqual(190) + }) + }) + it('should print handle failed steps', () => { recorder.start() let listeners = 0 diff --git a/test/unit/steps_test.js b/test/unit/steps_test.js index c4f8f0fe9..ce05e46a0 100644 --- a/test/unit/steps_test.js +++ b/test/unit/steps_test.js @@ -1,5 +1,5 @@ import sinon from 'sinon' -import Step, { MetaStep } from '../../lib/step.js' +import Step, { MetaStep, FuncStep } from '../../lib/step.js' import event from '../../lib/event.js' import { secret } from '../../lib/secret.js' import { expect } from 'chai' @@ -90,6 +90,22 @@ describe('Steps', () => { expect(action.called) expect(step.status).is.equal('success') }) + + it('should keep start time of the first attempt when retried', () => { + step.startTime = 1000 + step.run() + expect(step.startTime).is.equal(1000) + }) + }) + }) + + describe('FuncStep', () => { + it('should keep start time of the first attempt when retried', () => { + const funcStep = new FuncStep('doSomething') + funcStep.setCallable(() => 'done') + funcStep.startTime = 1000 + expect(funcStep.run()).is.equal('done') + expect(funcStep.startTime).is.equal(1000) }) })