Skip to content

Commit

Permalink
Merge branch 'fix-actionid'
Browse files Browse the repository at this point in the history
Add a random part in the generated ActionId
  • Loading branch information
Jean Aunis committed Mar 2, 2020
2 parents 2114629 + 324fe64 commit 3bfbd18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/AmiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ class AmiClient extends EventEmitter{
return true;
}

/**
*
* @private
*/
_random() {
return Math.floor(Math.random() * (10 ** 10));
}

/**
*
* @param prefix
Expand All @@ -325,7 +333,7 @@ class AmiClient extends EventEmitter{
*/
_genActionId(prefix){
prefix = prefix || '';
return `${prefix}${Date.now()}`;
return `${prefix}${Date.now()}-${this._random()}`;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion test/amiClientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,8 @@ describe('Ami Client internal functionality', function(){
client = new AmiClient({dontDeleteSpecActionId: true});
client.connect(USERNAME, SECRET, {port: socketOptions.port}).then(() => {
client.once('response', response => {
assert.ok(/^--spec_\d{13}$/.test(response.ActionID));
console.log("actionid = ", response.ActionID);
assert.ok(/^--spec_\d{13}-\d{1,10}$/.test(response.ActionID));
done();
})
.action({Action: 'Ping'});
Expand Down

0 comments on commit 3bfbd18

Please sign in to comment.