mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-31 09:51:52 +00:00
- Moved `withTimeout` implementation to `src/lock-utils.mjs` and exported it correctly. - Removed duplicate local definitions of `withTimeout`, `mergeRelayList`, and `secureRandom` in `src/lock-ops.mjs` and `src/lock-publisher.mjs`. - Fixed imports in `src/lock-ops.mjs`, `src/lock-publisher.mjs`, and `src/relay-health.mjs` to use `src/lock-utils.mjs` consistently. - Updated `test/utils.test.mjs` and `test/utils-async.test.mjs` to fix broken imports and test definitions. - Verified `npm run lock:complete` and `npm run scheduler:daily` execute correctly. - Updated `src/todo/TODO_2026-02-20T03-00-00Z.md` to mark verification task as completed. Co-authored-by: PR0M3TH3AN <[email protected]>
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert';
|
|
import { withTimeout } from '../src/lock-utils.mjs';
|
|
|
|
describe('Async Utilities', () => {
|
|
describe('withTimeout', () => {
|
|
it('resolves when promise completes before timeout', async () => {
|
|
const result = await withTimeout(
|
|
new Promise((resolve) => setTimeout(() => resolve('success'), 10)),
|
|
200,
|
|
'Timed out'
|
|
);
|
|
assert.strictEqual(result, 'success');
|
|
});
|
|
|
|
it('rejects when promise times out', async () => {
|
|
try {
|
|
await withTimeout(
|
|
new Promise((resolve) => setTimeout(() => resolve('success'), 200)),
|
|
10,
|
|
'Operation timed out'
|
|
);
|
|
assert.fail('Should have rejected');
|
|
} catch (err) {
|
|
assert.strictEqual(err.message, 'Operation timed out');
|
|
}
|
|
});
|
|
|
|
it('clears timeout on success', async () => {
|
|
const result = await withTimeout(
|
|
Promise.resolve('fast'),
|
|
1000,
|
|
'timeout'
|
|
);
|
|
assert.strictEqual(result, 'fast');
|
|
});
|
|
|
|
it('propagates original promise rejection', async () => {
|
|
try {
|
|
await withTimeout(
|
|
Promise.reject(new Error('Original error')),
|
|
100,
|
|
'Timeout'
|
|
);
|
|
assert.fail('Should have rejected');
|
|
} catch (err) {
|
|
assert.strictEqual(err.message, 'Original error');
|
|
}
|
|
});
|
|
});
|
|
});
|