0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-fixed-queue.js
Anatoli Papirovski 9a3ae2fe9d
lib: expose FixedQueue internally and fix nextTick bug
A bug was introduced together with the FixedQueue implementation for
process.nextTick which meant that the queue wouldn't necessarily
fully clear on each run through. Fix it and abstract the data
structure into an internal module that can later be used elsewhere.

PR-URL: https://github.com/nodejs/node/pull/20468
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-05-06 07:21:32 +02:00

35 lines
842 B
JavaScript

// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const FixedQueue = require('internal/fixed_queue');
{
const queue = new FixedQueue();
assert.strictEqual(queue.head, queue.tail);
assert(queue.isEmpty());
queue.push('a');
assert(!queue.isEmpty());
assert.strictEqual(queue.shift(), 'a');
assert.strictEqual(queue.shift(), null);
}
{
const queue = new FixedQueue();
for (let i = 0; i < 2047; i++)
queue.push('a');
assert(queue.head.isFull());
queue.push('a');
assert(!queue.head.isFull());
assert.notStrictEqual(queue.head, queue.tail);
for (let i = 0; i < 2047; i++)
assert.strictEqual(queue.shift(), 'a');
assert.strictEqual(queue.head, queue.tail);
assert(!queue.isEmpty());
assert.strictEqual(queue.shift(), 'a');
assert(queue.isEmpty());
}