From 8ec4e00e02bea45e7a19c12610ba0af3852c02cd Mon Sep 17 00:00:00 2001 From: Dave Kelsey Date: Mon, 10 Jun 2024 09:24:09 +0100 Subject: [PATCH] Address test flake due to timing (#1595) 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 --- packages/caliper-core/test/common/core/messages/message.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/caliper-core/test/common/core/messages/message.js b/packages/caliper-core/test/common/core/messages/message.js index 6b776cb37..f655ff19d 100644 --- a/packages/caliper-core/test/common/core/messages/message.js +++ b/packages/caliper-core/test/common/core/messages/message.js @@ -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); }) }) })