-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mu): add missing tests for cron monitor functions #747
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) | ||
}) | ||
}) |