2019-08-30 14:47:54 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const { test } = require('tap')
|
|
|
|
const { MAX_MSGID } = require('../../../../lib/client/constants')
|
|
|
|
const idGeneratorFactory = require('../../../../lib/client/message-tracker/id-generator')
|
|
|
|
|
|
|
|
test('starts at 0', async t => {
|
|
|
|
const nextID = idGeneratorFactory()
|
|
|
|
const currentID = nextID()
|
2021-04-05 05:34:59 +00:00
|
|
|
t.equal(currentID, 1)
|
2019-08-30 14:47:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('handles wrapping around', async t => {
|
|
|
|
const nextID = idGeneratorFactory(MAX_MSGID - 2)
|
|
|
|
|
|
|
|
let currentID = nextID()
|
2021-04-05 05:34:59 +00:00
|
|
|
t.equal(currentID, MAX_MSGID - 1)
|
2019-08-30 14:47:54 +00:00
|
|
|
|
|
|
|
currentID = nextID()
|
2021-04-05 05:34:59 +00:00
|
|
|
t.equal(currentID, 1)
|
2019-08-30 14:47:54 +00:00
|
|
|
})
|