Skip to content

Commit

Permalink
Fix timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
SketchingDev committed Aug 4, 2023
1 parent 0cb690f commit 4e226b8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/genesys-web-messaging-tester-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"web-messaging-tester": "lib/index.js"
},
"dependencies": {
"@ovotech/genesys-web-messaging-tester": "2.0.5-beta.2",
"@ovotech/genesys-web-messaging-tester": "2.0.5-beta.3",
"chalk": "^4.1.2",
"ci-info": "^3.5.0",
"commander": "^11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/genesys-web-messaging-tester/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ovotech/genesys-web-messaging-tester",
"version": "2.0.5-beta.2",
"version": "2.0.5-beta.3",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/genesys-web-messaging-tester/src/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class Conversation {
return text;
},
},
timeoutInSeconds + this.timeoutCompensation,
timeoutInSeconds,
);
}

Expand All @@ -296,7 +296,7 @@ export class Conversation {
return pattern.toString();
},
},
timeoutInSeconds + this.timeoutCompensation,
timeoutInSeconds,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,19 @@ export class ReorderedMessageDelayer extends EventEmitter implements MessageDela
() => this.emitMessagesAfterSilence(),
ReorderedMessageDelayer.INTERVAL,
);
ReorderedMessageDelayer.debugger('Interval started');
}
}

private stopInterval(): void {
if (this.intervalReference) {
this.intervalClear(this.intervalReference);
this.intervalReference = undefined;
ReorderedMessageDelayer.debugger('Interval stopped');
}
}

private emitMessagesAfterSilence(): void {
if (this.messages.length === 0) {
this.stopInterval();
return;
}

const result = orderByTimestamp(this.messages);
if (result.wasRearranged) {
ReorderedMessageDelayer.debugger(
Expand All @@ -101,19 +98,27 @@ export class ReorderedMessageDelayer extends EventEmitter implements MessageDela
if (isStructuredMessage(this.messages[0].response)) {
const ageOfMessageInMs = now - this.messages[0].received.getTime();
if (ageOfMessageInMs >= ReorderedMessageDelayer.SILENCE_TO_WAIT_IN_MS) {
this.emit('message', this.messages.shift()?.response);
const message = this.messages.shift()?.response;
this.emit('message', message);
ReorderedMessageDelayer.debugger('Emitted message with timestamp: %O', {
msDelayed: ageOfMessageInMs,
message,
});
} else {
finished = true;
}
} else {
const message = this.messages.shift()?.response;
// No timestamp so just emit
this.emit('message', this.messages.shift()?.response);
ReorderedMessageDelayer.debugger('Emitted message without timestamp');
this.emit('message', message);
ReorderedMessageDelayer.debugger('Emitted message without timestamp %O', message);
}
} while (!finished && this.messages.length > 0);

if (this.messages.length === 0) {
this.stopInterval();
return;
}
}

public get delay(): number {
Expand Down
15 changes: 13 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@ovotech/genesys-web-messaging-tester-cli@workspace:packages/genesys-web-messaging-tester-cli"
dependencies:
"@ovotech/genesys-web-messaging-tester": 2.0.5-beta.2
"@ovotech/genesys-web-messaging-tester": 2.0.5-beta.3
"@types/humanize-duration": ^3.27.1
"@types/jest": ^29.0.3
"@types/jest-when": ^3.5.2
Expand Down Expand Up @@ -959,7 +959,7 @@ __metadata:
languageName: unknown
linkType: soft

"@ovotech/[email protected].2, @ovotech/genesys-web-messaging-tester@workspace:packages/genesys-web-messaging-tester":
"@ovotech/[email protected].3, @ovotech/genesys-web-messaging-tester@workspace:packages/genesys-web-messaging-tester":
version: 0.0.0-use.local
resolution: "@ovotech/genesys-web-messaging-tester@workspace:packages/genesys-web-messaging-tester"
dependencies:
Expand Down Expand Up @@ -987,6 +987,17 @@ __metadata:
languageName: unknown
linkType: soft

"@ovotech/genesys-web-messaging-tester@npm:2.0.5-beta.2":
version: 2.0.5-beta.2
resolution: "@ovotech/genesys-web-messaging-tester@npm:2.0.5-beta.2"
dependencies:
debug: ^4.3.3
uuid: ^9.0.0
ws: ^8.13.0
checksum: ec64ae96df500021dafcc963557ce944cbdcc069ab5b746ca51cc5d79fe241e2dcc3a526b713b20f84208b143cfc0e86f67472d1e66e4e878a20997de2364e86
languageName: node
linkType: hard

"@sideway/address@npm:^4.1.3":
version: 4.1.4
resolution: "@sideway/address@npm:4.1.4"
Expand Down

0 comments on commit 4e226b8

Please sign in to comment.