fix: harden PrestaShop automation jobs
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { createJobRuntime } = require('../src/job-runtime');
|
||||
|
||||
test('lock is released after success and after failure', async () => {
|
||||
const released = [];
|
||||
const Core = {
|
||||
getLock: async name => name,
|
||||
extendLockTime: async () => true,
|
||||
releaseLock: async id => released.push(id),
|
||||
};
|
||||
const runtime = createJobRuntime(Core, { error() {}, warn() {} });
|
||||
|
||||
assert.equal(await runtime.withRenewedLock('ok', 5000, async valid => valid() && 7), 7);
|
||||
await assert.rejects(() => runtime.withRenewedLock('fail', 5000, async () => { throw new Error('boom'); }), /boom/);
|
||||
assert.deepEqual(released, ['ok', 'fail']);
|
||||
});
|
||||
|
||||
test('stop waits for tracked work and blocks subsequent runs until start', async () => {
|
||||
const runtime = createJobRuntime({}, console);
|
||||
let finish;
|
||||
const active = runtime.track(() => new Promise(resolve => { finish = resolve; }));
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
const stopping = runtime.stop();
|
||||
finish('done');
|
||||
await stopping;
|
||||
assert.equal(await active, 'done');
|
||||
assert.equal(await runtime.track(async () => 'blocked'), null);
|
||||
runtime.start();
|
||||
assert.equal(await runtime.track(async () => 'running'), 'running');
|
||||
});
|
||||
Reference in New Issue
Block a user