-
-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathtest-stream-writable-write-writev-finish.js
More file actions
158 lines (119 loc) · 3.45 KB
/
Copy pathtest-stream-writable-write-writev-finish.js
File metadata and controls
158 lines (119 loc) · 3.45 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*<replacement>*/
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
var stream = require('../../');
// ensure consistency between the finish event when using cork()
// and writev and when not using them
{
var writable = new stream.Writable();
writable._write = function (chunks, encoding, cb) {
cb(new Error('write test error'));
};
var firstError = false;
writable.on('finish', common.mustCall(function () {
assert.strictEqual(firstError, true);
}));
writable.on('prefinish', common.mustCall());
writable.on('error', common.mustCall(function (er) {
assert.strictEqual(er.message, 'write test error');
firstError = true;
}));
writable.end('test');
}
{
var _writable = new stream.Writable();
_writable._write = function (chunks, encoding, cb) {
setImmediate(cb, new Error('write test error'));
};
var _firstError = false;
_writable.on('finish', common.mustCall(function () {
assert.strictEqual(_firstError, true);
}));
_writable.on('prefinish', common.mustCall());
_writable.on('error', common.mustCall(function (er) {
assert.strictEqual(er.message, 'write test error');
_firstError = true;
}));
_writable.end('test');
}
{
var _writable2 = new stream.Writable();
_writable2._write = function (chunks, encoding, cb) {
cb(new Error('write test error'));
};
_writable2._writev = function (chunks, cb) {
cb(new Error('writev test error'));
};
var _firstError2 = false;
_writable2.on('finish', common.mustCall(function () {
assert.strictEqual(_firstError2, true);
}));
_writable2.on('prefinish', common.mustCall());
_writable2.on('error', common.mustCall(function (er) {
assert.strictEqual(er.message, 'writev test error');
_firstError2 = true;
}));
_writable2.cork();
_writable2.write('test');
setImmediate(function () {
_writable2.end('test');
});
}
{
var _writable3 = new stream.Writable();
_writable3._write = function (chunks, encoding, cb) {
setImmediate(cb, new Error('write test error'));
};
_writable3._writev = function (chunks, cb) {
setImmediate(cb, new Error('writev test error'));
};
var _firstError3 = false;
_writable3.on('finish', common.mustCall(function () {
assert.strictEqual(_firstError3, true);
}));
_writable3.on('prefinish', common.mustCall());
_writable3.on('error', common.mustCall(function (er) {
assert.strictEqual(er.message, 'writev test error');
_firstError3 = true;
}));
_writable3.cork();
_writable3.write('test');
setImmediate(function () {
_writable3.end('test');
});
}
// Regression test for
// https://github.com/nodejs/node/issues/13812
{
var rs = new stream.Readable();
rs.push('ok');
rs.push(null);
rs._read = function () {};
var ws = new stream.Writable();
var _firstError4 = false;
ws.on('finish', common.mustCall(function () {
assert.strictEqual(_firstError4, true);
}));
ws.on('error', common.mustCall(function () {
_firstError4 = true;
}));
ws._write = function (chunk, encoding, done) {
setImmediate(done, new Error());
};
rs.pipe(ws);
}
{
var _rs = new stream.Readable();
_rs.push('ok');
_rs.push(null);
_rs._read = function () {};
var _ws = new stream.Writable();
_ws.on('finish', common.mustNotCall());
_ws.on('error', common.mustCall());
_ws._write = function (chunk, encoding, done) {
done(new Error());
};
_rs.pipe(_ws);
}