Files
modules/scheduling-queues/hyper-p2p-cron-gossip/test/test.js
T
2026-05-20 22:56:32 -04:00

38 lines
962 B
JavaScript

require('bare-process/global')
const test = require('brittle')
const { HyperP2PCronGossip, PROTOCOL } = require('../index.js')
test('exports', (t) => {
t.ok(HyperP2PCronGossip)
t.is(PROTOCOL, 'cron-gossip/v1')
})
test('schedule tick', async (t) => {
const m = new HyperP2PCronGossip()
m.schedule('@every 10ms', 'job-1')
const fired = m.tick(Date.now() + 20)
t.alike(fired, ['job-1'])
await m.close()
})
test('validation', async (t) => {
const m = new HyperP2PCronGossip()
try { m.schedule('', 'j') } catch (e) { t.ok(e) }
await m.close()
})
test('remote gossip', async (t) => {
const m = new HyperP2PCronGossip()
m._onGossip({ type: 'cron-fire', jobId: 'remote', at: 42 })
t.is(m.get('remote').lastRun, 42)
await m.close()
})
test('getStats', async (t) => {
const m = new HyperP2PCronGossip()
m.schedule('@every 1s', 'a')
t.is(m.getStats().protocol, 'cron-gossip/v1')
t.is(m.getStats().scheduled, 1)
await m.close()
})