mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-15 19:57:07 +08:00
* fix: harden task lifecycle and scheduler readiness * fix: confine log writes to the configured log directory * fix: verify complete build artifacts and untracked inputs * fix: reconcile scheduler state and make stop win startup races * fix: isolate cron generations and serialize scheduler recovery
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const test = require('node:test');
|
|
const path = require('node:path');
|
|
const dayjs = require('dayjs');
|
|
const load = require('../helpers/load-security-module.cjs');
|
|
|
|
test('subscription becomes idle and closes its log even when completion logging fails', async () => {
|
|
const updates = [];
|
|
let closed = 0;
|
|
let notified = 0;
|
|
const Subscription = load(path.resolve('back/services/subscription.ts'), {
|
|
'../config': {},
|
|
'../data/subscription': {
|
|
SubscriptionModel: { update: async (values) => updates.push(values) },
|
|
SubscriptionStatus: { idle: 1 },
|
|
},
|
|
'../data/cron': {},
|
|
'../config/util': { handleLogPath: async () => '/tmp/unused-log' },
|
|
'../config/const': { LOG_END_SYMBOL: 'end' },
|
|
'../config/subscription': {},
|
|
'../shared/i18n': { t: (s) => s, tf: (s) => s },
|
|
'../shared/pLimit': {},
|
|
'../shared/logReader': {},
|
|
'../shared/logStreamManager': {
|
|
logStreamManager: {
|
|
write: async () => {
|
|
throw new Error('ENOSPC');
|
|
},
|
|
closeStream: async () => {
|
|
closed++;
|
|
throw new Error('ENOSPC');
|
|
},
|
|
},
|
|
},
|
|
'./schedule': {},
|
|
'./sock': {},
|
|
'./sshKey': {},
|
|
'./cron': {},
|
|
}).default;
|
|
const service = new Subscription(
|
|
{},
|
|
{},
|
|
{ sendMessage: () => notified++ },
|
|
{},
|
|
{},
|
|
);
|
|
service.getDb = async () => ({ id: 1, log_path: 'log' });
|
|
const callbacks = service.taskCallbacks({ id: 1 });
|
|
await assert.rejects(callbacks.onEnd(undefined, dayjs(), 1), /ENOSPC/);
|
|
assert.equal(closed, 1);
|
|
assert.equal(updates.at(-1).status, 1);
|
|
assert.equal(notified, 1);
|
|
});
|