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.'