Skip to content

Commit

Permalink
test(mu): add missing tests for cron monitor functions #747
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdn91 committed Jul 19, 2024
1 parent ee4617c commit e2d37ec
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions servers/mu/src/domain/clients/cron.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as assert from 'node:assert'
import { describe, test } from 'node:test'

import cron from './cron.js'
import createLogger from '../logger.js'

describe('cron', () => {
describe('initCronProcsWith', () => {
test('should not start process if proc file could not be read', async () => {
await cron.initCronProcsWith({
readProcFile: () => undefined,
startMonitoredProcess: async () => {
assert.fail('should not start process')
}
})()
})

describe('processing proc file runs successfully when not initial run and skips subsequent runs', async () => {
let saveProcsCalls = 0
const initCronProcs = await cron.initCronProcsWith({
readProcFile: () => ({ 1: '1' }),
startMonitoredProcess: async () => Promise.resolve(),
saveProcs: () => {
console.log('calling save procs')
saveProcsCalls++
return Promise.resolve()
}
})

test('should start process by reading proc file and saving procs', async () => {
await initCronProcs()
assert.equal(saveProcsCalls, 1)
})

test('should not process any more times after initial process', async () => {
await initCronProcs()
assert.equal(saveProcsCalls, 1)
})
})
})

describe('startMonitoredProcessWith', () => {

})

describe('killMonitoredProcessWith', () => {
const logger = createLogger('kill-monitor-test')
test('should not kill process if process is not a running cron', async () => {
const killMonitoredProcess = await cron.killMonitoredProcessWith({
PROC_FILE_PATH: 'test',
logger,
monitorGauge: () => ({
dec: () => {}
}),
saveProcs: async () => Promise.resolve()
})
await killMonitoredProcess({ processId: 1 }).catch(() => {
assert.ok('should catch error')
})
})
})
})

0 comments on commit e2d37ec

Please sign in to comment.