summaryrefslogtreecommitdiff
path: root/test/parallel/test-fixed-queue.js
blob: a50be1309a5ea8da4648fef27ed856b73745915b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 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());
}