Skip to content
Permalink
Browse files
fix(core): corrected error message produced by StageManager when asyn…
…c operations time out
  • Loading branch information
jan-molak committed Feb 18, 2021
1 parent 458a021 commit 54e2c49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
@@ -63,7 +63,7 @@ describe('StageManager', () => {
*/
it('provides details should the work in progress fail to complete', () => {

const timeout = Duration.ofSeconds(1);
const timeout = Duration.ofMilliseconds(50);
const stageManager = new StageManager(timeout, new Clock());

stageManager.notifyOf(new AsyncOperationAttempted(
@@ -76,17 +76,13 @@ describe('StageManager', () => {
CorrelationId.create(),
));

// todo: remove
const queueDesc = JSON.stringify(Array.from((stageManager as any).wip.wip.values()), null, 4);
expect((stageManager as any).wip.wip.size, queueDesc).to.equal(2);

return expect(stageManager.waitForNextCue()).to.be.rejected.then(error => {
const lines = error.message.split('\n');

expect(lines, `error.message[${ error.message }]`).to.have.lengthOf(3);
expect(lines[0]).to.equal('2 async operations have failed to complete within a 1s cue timeout:');
expect(lines[1], error.message).to.match(/^1s.*?- \[Service 1] Starting...$/);
expect(lines[2], error.message).to.match(/^1s.*?- \[Service 2] Starting...$/);
expect(lines, `message: \n${ error.message }`).to.have.lengthOf(3);
expect(lines[0]).to.equal('2 async operations have failed to complete within a 50ms cue timeout:');
expect(lines[1], error.message).to.match(/^\d+ms.*?- \[Service 1] Starting...$/);
expect(lines[2], error.message).to.match(/^\d+ms.*?- \[Service 2] Starting...$/);
});
});

@@ -131,10 +131,7 @@ class WIP {
descriptionOfTimedOutOperations(): string {
const now = this.clock.now();

const timedOutOperations = Array.from(this.wip.values())
.filter(op => now.diff(op.startedAt).isGreaterThanOrEqualTo(this.cueTimeout));

return timedOutOperations.reduce(
return this.activeOperations().reduce(
(acc, op) => acc.concat(`${ now.diff(op.startedAt) } - ${ op.taskDescription.value }`),
[`${ this.header(this.wip.size) } within a ${ this.cueTimeout } cue timeout:`],
).join('\n');
@@ -154,6 +151,10 @@ class WIP {
this.failedOperations.length = 0;
}

private activeOperations() {
return Array.from(this.wip.values());
}

private header(numberOfFailures): string {
return numberOfFailures === 1
? `1 async operation has failed to complete`

0 comments on commit 54e2c49

Please sign in to comment.