Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion lib/internal/priority_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ module.exports = class PriorityQueue {
}

peekBottom() {
return this.#heap[this.#size];
const compare = this.#compare;
const heap = this.#heap;
const size = this.#size;
let bottom = heap[size];
for (let pos = (size >> 1) + 1; pos < size; pos++) {
if (compare(heap[pos], bottom) > 0)
bottom = heap[pos];
}
return bottom;
}

percolateDown(pos) {
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-runner-mock-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ describe('Mock Timers Test Suite', () => {
assert.strictEqual(Date.now(), 9999);
});

it('should trigger all timers when the longest one is scheduled first', (t) => {
t.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
const results = [];

globalThis.setTimeout(() => results.push(1), 9999);
globalThis.setTimeout(() => results.push(3), 8888);
globalThis.setTimeout(() => results.push(2), 8888);
t.mock.timers.runAll();

assert.deepStrictEqual(results, [3, 2, 1]);
assert.strictEqual(Date.now(), 9999);
});

it('should not error if there are not timers to run', (t) => {
t.mock.timers.enable();
t.mock.timers.runAll();
Expand Down