Skip to content

Commit

Permalink
Address test flake due to timing (#1595)
Browse files Browse the repository at this point in the history
The original test assumes that the 2 generated dates will occur on the
exact same millisecond which is going to be unlikely. This fix allows
for upto a 5 second discrepancy

Signed-off-by: Dave Kelsey <[email protected]>
  • Loading branch information
Dave Kelsey authored Jun 10, 2024
1 parent b97c4b3 commit 8ec4e00
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/caliper-core/test/common/core/messages/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,13 @@ describe('Message', () => {

it("should set the current date if the date is not provided", () => {
const message = new Message(mockSender, mockRecipients, mockType, mockContent);
const firstDate = new Date();
const stringifiedMessage = message.stringify();
const decodedMessage = JSON.parse(stringifiedMessage);

decodedMessage.date.should.equal(new Date().toISOString());
const secondDate = new Date(decodedMessage.date);
const millisecondDifference = secondDate - firstDate;
// allow for upto 5 second discrepancy
chai.assert(millisecondDifference < 5 * 1000);
})
})
})

0 comments on commit 8ec4e00

Please sign in to comment.