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]]);
|
||||
});
|
||||
|
||||
@@ -56,12 +56,20 @@ test('rejects non-retryable 4xx and invalid JSON', async t => {
|
||||
test('times out stalled requests', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
// Timer timeoutu w fetchWithTimeout jest `unref`-owany, a Core.fetch nigdy się tu nie rozwiązuje,
|
||||
// więc na prawdziwych timerach pętla zdarzeń pustoszeje i node:test anuluje ten test.
|
||||
// Mockowany setTimeout pozwala wysterować timeout ręcznie przez tick().
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
Core.fetch = async () => new Promise(() => {});
|
||||
const api = new PrestashopApi('https://shop.example', 'secret', true, {
|
||||
timeoutMs: 5, maxGetAttempts: 1,
|
||||
});
|
||||
|
||||
await assert.rejects(() => api.makeRequest('orders', 'GET'), /timed out/);
|
||||
const pending = api.makeRequest('orders', 'GET');
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
t.mock.timers.tick(10);
|
||||
|
||||
await assert.rejects(() => pending, /timed out/);
|
||||
});
|
||||
|
||||
test('preserves the explicitly allowed product partial-success compatibility path', async t => {
|
||||
|
||||
Reference in New Issue
Block a user