Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: topic message warning branch uses xor #271

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading