Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/step/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion lib/step/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 10 additions & 0 deletions test/unit/actor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion test/unit/steps_test.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
})
})

Expand Down
Loading