src: disable fast math on arm
[platform/upstream/nodejs.git] / test / parallel / test-stream-big-packet.js
1 var common = require('../common');
2 var assert = require('assert');
3 var util = require('util');
4 var stream = require('stream');
5
6 var passed = false;
7
8 function PassThrough () {
9   stream.Transform.call(this);
10 };
11 util.inherits(PassThrough, stream.Transform);
12 PassThrough.prototype._transform = function (chunk, encoding, done) {
13   this.push(chunk);
14   done();
15 };
16
17 function TestStream () {
18   stream.Transform.call(this);
19 };
20 util.inherits(TestStream, stream.Transform);
21 TestStream.prototype._transform = function (chunk, encoding, done) {
22   if (!passed) {
23     // Char 'a' only exists in the last write
24     passed = chunk.toString().indexOf('a') >= 0;
25   }
26   done();
27 };
28
29 var s1 = new PassThrough();
30 var s2 = new PassThrough();
31 var s3 = new TestStream();
32 s1.pipe(s3);
33 // Don't let s2 auto close which may close s3
34 s2.pipe(s3, {end: false});
35
36 // We must write a buffer larger than highWaterMark
37 var big = new Buffer(s1._writableState.highWaterMark + 1);
38 big.fill('x');
39
40 // Since big is larger than highWaterMark, it will be buffered internally.
41 assert(!s1.write(big));
42 // 'tiny' is small enough to pass through internal buffer.
43 assert(s2.write('tiny'));
44
45 // Write some small data in next IO loop, which will never be written to s3
46 // Because 'drain' event is not emitted from s1 and s1 is still paused
47 setImmediate(s1.write.bind(s1), 'later');
48
49 // Assert after two IO loops when all operations have been done.
50 process.on('exit', function () {
51   assert(passed, 'Large buffer is not handled properly by Writable Stream');
52 });