Files
qinglong/test/back/subscription-cleanup.test.cjs
T
whyour a94e665054 fix: 修复任务生命周期与调度就绪,优化执行和构建开销 (#3069)
* 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
2026-09-13 00:32:41 +08:00

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);
});