chore: upgrade @orbito/api-lib to 3.3.3
Lock TTL is now passed in seconds, matching what the core lock RPC methods expect and what the 3.x SDK documents as ttlSeconds. The presta-api timeout test no longer drains the event loop: it drives the unref-ed timeout timer through node:test mock timers instead of real ones. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpoFvfAbnMmkSJFRc867XA
This commit is contained in:
@@ -11,8 +11,8 @@ test('lock is released after success and after failure', async () => {
|
||||
};
|
||||
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.equal(await runtime.withRenewedLock('ok', 5, async valid => valid() && 7), 7);
|
||||
await assert.rejects(() => runtime.withRenewedLock('fail', 5, async () => { throw new Error('boom'); }), /boom/);
|
||||
assert.deepEqual(released, ['ok', 'fail']);
|
||||
});
|
||||
|
||||
@@ -29,3 +29,26 @@ test('stop waits for tracked work and blocks subsequent runs until start', async
|
||||
runtime.start();
|
||||
assert.equal(await runtime.track(async () => 'running'), 'running');
|
||||
});
|
||||
|
||||
test('lock TTL is forwarded to Core in seconds, without conversion', async t => {
|
||||
t.mock.timers.enable({ apis: ['setInterval'] });
|
||||
const getLockCalls = [];
|
||||
const extendCalls = [];
|
||||
const Core = {
|
||||
getLock: async (name, ttl) => { getLockCalls.push([name, ttl]); return 'lock-1'; },
|
||||
extendLockTime: async (id, ttl) => { extendCalls.push([id, ttl]); return true; },
|
||||
releaseLock: async () => true,
|
||||
};
|
||||
const runtime = createJobRuntime(Core, { error() {}, warn() {} });
|
||||
|
||||
let finish;
|
||||
const run = runtime.withRenewedLock('ttl', 5, () => new Promise(resolve => { finish = resolve; }));
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
// Interwał odnowienia to ttlSeconds * 1000 / 3 = ~1666 ms, więc jeden tick wystarczy.
|
||||
t.mock.timers.tick(1700);
|
||||
finish('done');
|
||||
assert.equal(await run, 'done');
|
||||
|
||||
assert.deepEqual(getLockCalls, [['ttl', 5]]);
|
||||
assert.deepEqual(extendCalls, [['lock-1', 5]]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user