summaryrefslogtreecommitdiff
path: root/test/parallel/test-stream-push-order.js
blob: f09cf95f370bce9c3ea81150c8ea7a295b107d52 (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
'use strict';
require('../common');
var Readable = require('stream').Readable;
var assert = require('assert');

var s = new Readable({
  highWaterMark: 20,
  encoding: 'ascii'
});

var list = ['1', '2', '3', '4', '5', '6'];

s._read = function(n) {
  var one = list.shift();
  if (!one) {
    s.push(null);
  } else {
    var two = list.shift();
    s.push(one);
    s.push(two);
  }
};

s.read(0);

// ACTUALLY [1, 3, 5, 6, 4, 2]

process.on('exit', function() {
  assert.deepEqual(s._readableState.buffer,
                   ['1', '2', '3', '4', '5', '6']);
  console.log('ok');
});