From cff0c03b59a142c102d292dcaa9ef89d91bc7f95 Mon Sep 17 00:00:00 2001 From: markuczy <129275100+markuczy@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:31:42 +0200 Subject: [PATCH] fix: topic message warning branch uses xor (#271) * fix: warning branch uses xor * fix: message starts with id 1 and removed logs --- libs/accelerator/src/lib/topic/message.ts | 2 +- libs/accelerator/src/lib/topic/topic.spec.ts | 17 +++++++++++++++++ libs/accelerator/src/lib/topic/topic.ts | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libs/accelerator/src/lib/topic/message.ts b/libs/accelerator/src/lib/topic/message.ts index 63e488d1..76dcae14 100644 --- a/libs/accelerator/src/lib/topic/message.ts +++ b/libs/accelerator/src/lib/topic/message.ts @@ -4,7 +4,7 @@ declare global { } } -window['onecxMessageId'] = 0 +window['onecxMessageId'] = 1 export class Message { timestamp: number diff --git a/libs/accelerator/src/lib/topic/topic.spec.ts b/libs/accelerator/src/lib/topic/topic.spec.ts index b6c006ea..7972d8d2 100644 --- a/libs/accelerator/src/lib/topic/topic.spec.ts +++ b/libs/accelerator/src/lib/topic/topic.spec.ts @@ -184,6 +184,8 @@ describe('Topic', () => { // initialize topic testTopic1.publish('initMsg') + + jest.resetAllMocks() }) it('should have value if incoming id is greater than previous id', () => { @@ -282,5 +284,20 @@ describe('Topic', () => { 'Message was dropped because of equal timestamps, because there was an old style message in the system. Please upgrade all libraries to the latest version.' ) }) + + it('should have no value and no warning if incoming timestamp is equal to previous timestamp when incoming message has smaller id then current', () => { + jest.spyOn(console, 'warn') + previousMessage.data = 'msg1' + ;(previousMessage).id = 2 + previousMessage.timestamp = 3 + incomingMessage.data.data = 'msg2' + incomingMessage.data.id = 1 + incomingMessage.data.timestamp = 3 + ;(testTopic1).data.next(previousMessage) + ;(testTopic1).onMessage(incomingMessage) + + expect(values1).toEqual(['initMsg', 'msg1']) + expect(console.warn).toHaveBeenCalledTimes(0) + }) }) }) diff --git a/libs/accelerator/src/lib/topic/topic.ts b/libs/accelerator/src/lib/topic/topic.ts index e5aa5822..ae51e233 100644 --- a/libs/accelerator/src/lib/topic/topic.ts +++ b/libs/accelerator/src/lib/topic/topic.ts @@ -169,7 +169,7 @@ export class Topic extends TopicPublisher implements Subscribable { this.data.value && this.isInit && (m.data).timestamp === this.data.value.timestamp && - ((m.data).id || this.data.value.id) + (((m.data).id && !this.data.value.id) || (!(m.data).id && this.data.value.id)) ) { console.warn( 'Message was dropped because of equal timestamps, because there was an old style message in the system. Please upgrade all libraries to the latest version.'