mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-05 20:31:54 +00:00
Fix: Move withTimeout tests to isolated file to avoid MockTimer interference
Moved unit tests for `withTimeout` from `test/utils.test.mjs` to `test/utils-async.test.mjs`. This prevents potential interference from `MockTimers` enabled in `test/utils.test.mjs` which could affect `setTimeout` behavior in async tests. Increased timeout margins in `withTimeout` tests for better reliability in CI. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
04abfa9c24
commit
b644aa6db8
3 files changed
+3538
-51
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import { withTimeout } from '../src/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');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
+1
-51
@@ -2,7 +2,7 @@ import { describe, it, after } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { getIsoWeekStr, todayDateStr, nowUnix, ensureDir, detectPlatform, withTimeout } from '../src/utils.mjs';
|
||||
import { getIsoWeekStr, todayDateStr, nowUnix, ensureDir, detectPlatform } from '../src/utils.mjs';
|
||||
|
||||
describe('Date Utilities', () => {
|
||||
describe('todayDateStr', () => {
|
||||
@@ -184,53 +184,3 @@ describe('File Utilities', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Async Utilities', () => {
|
||||
describe('withTimeout', () => {
|
||||
it('resolves when promise completes before timeout', async () => {
|
||||
const result = await withTimeout(
|
||||
new Promise((resolve) => setTimeout(() => resolve('success'), 10)),
|
||||
100,
|
||||
'Timed out'
|
||||
);
|
||||
assert.strictEqual(result, 'success');
|
||||
});
|
||||
|
||||
it('rejects when promise times out', async () => {
|
||||
try {
|
||||
await withTimeout(
|
||||
new Promise((resolve) => setTimeout(() => resolve('success'), 100)),
|
||||
10,
|
||||
'Operation timed out'
|
||||
);
|
||||
assert.fail('Should have rejected');
|
||||
} catch (err) {
|
||||
assert.strictEqual(err.message, 'Operation timed out');
|
||||
}
|
||||
});
|
||||
|
||||
it('clears timeout on success', async () => {
|
||||
// This is hard to test directly without mocking setTimeout/clearTimeout
|
||||
// but we can verify it doesn't throw or hang.
|
||||
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');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user