Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
  • Loading branch information
gurgunday committed Apr 13, 2025
commit 4bba36510137c25e63c4fb3fd11ec93cbf23b0d9
35 changes: 35 additions & 0 deletions test/parallel/test-abort-controller-any-timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

require('../common');
const assert = require('assert');
const { describe, it } = require('node:test');

describe('AbortSignal.any() with timeout signals', () => {
it('should abort when the first timeout signal fires', async () => {
const signal = AbortSignal.any([AbortSignal.timeout(9000), AbortSignal.timeout(110000)]);

const abortPromise = new Promise((resolve, reject) => {
signal.addEventListener('abort', () => {
reject(signal.reason);
});

setTimeout(resolve, 15000);
});
Comment thread
gurgunday marked this conversation as resolved.
Resolved

// The promise should be aborted by the 9000ms timeout
const start = Date.now();
await assert.rejects(
() => abortPromise,
{
name: 'TimeoutError',
message: 'The operation was aborted due to timeout'
}
);

const duration = Date.now() - start;

// Verify the timeout happened at approximately the right time (with some margin)
assert.ok(duration >= 8900, `Timeout happened too early: ${duration}ms`);
assert.ok(duration < 11000, `Timeout happened too late: ${duration}ms`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this?
Can't we validate the reason is a timeout signal?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, does it look better?

});
});