Skip to content

Commit

Permalink
fix: topic message warning branch uses xor (#271)
Browse files Browse the repository at this point in the history
* fix: warning branch uses xor

* fix: message starts with id 1 and removed logs
  • Loading branch information
markuczy authored Jun 6, 2024
1 parent 44ab35e commit cff0c03
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libs/accelerator/src/lib/topic/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare global {
}
}

window['onecxMessageId'] = 0
window['onecxMessageId'] = 1

export class Message {
timestamp: number
Expand Down
17 changes: 17 additions & 0 deletions libs/accelerator/src/lib/topic/topic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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'
;(<any>previousMessage).id = 2
previousMessage.timestamp = 3
incomingMessage.data.data = 'msg2'
incomingMessage.data.id = 1
incomingMessage.data.timestamp = 3
;(<any>testTopic1).data.next(previousMessage)
;(<any>testTopic1).onMessage(incomingMessage)

expect(values1).toEqual(['initMsg', 'msg1'])
expect(console.warn).toHaveBeenCalledTimes(0)
})
})
})
2 changes: 1 addition & 1 deletion libs/accelerator/src/lib/topic/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class Topic<T> extends TopicPublisher<T> implements Subscribable<T> {
this.data.value &&
this.isInit &&
(<TopicMessage>m.data).timestamp === this.data.value.timestamp &&
((<TopicMessage>m.data).id || this.data.value.id)
(((<TopicMessage>m.data).id && !this.data.value.id) || (!(<TopicMessage>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.'
Expand Down

0 comments on commit cff0c03

Please sign in to comment.