Skip to content

Commit c7a9a2e

Browse files
committed
test: split out load-sensitive readline tests
Two test cases in `test-readline-interface` are sensitive to resource constraints (probably due to `\r` and `\n` not arriving within the appropriate delay to be treated as a single line ending). Move those tests to `sequential`. PR-URL: #14681 Fixes: #14674 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent fe54bc7 commit c7a9a2e

File tree

2 files changed

+87
-37
lines changed

2 files changed

+87
-37
lines changed

test/parallel/test-readline-interface.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// Flags: --expose_internals
2323
'use strict';
2424
const common = require('../common');
25+
2526
const assert = require('assert');
2627
const readline = require('readline');
2728
const internalReadline = require('internal/readline');
@@ -233,43 +234,6 @@ function isWarned(emitter) {
233234
// sending multiple newlines at once that does not end with a new line
234235
// and a `end` event(last line is)
235236

236-
// \r\n should emit one line event, not two
237-
{
238-
const fi = new FakeInput();
239-
const rli = new readline.Interface(
240-
{ input: fi, output: fi, terminal: terminal }
241-
);
242-
const expectedLines = ['foo', 'bar', 'baz', 'bat'];
243-
let callCount = 0;
244-
rli.on('line', function(line) {
245-
assert.strictEqual(line, expectedLines[callCount]);
246-
callCount++;
247-
});
248-
fi.emit('data', expectedLines.join('\r\n'));
249-
assert.strictEqual(callCount, expectedLines.length - 1);
250-
rli.close();
251-
}
252-
253-
// \r\n should emit one line event when split across multiple writes.
254-
{
255-
const fi = new FakeInput();
256-
const rli = new readline.Interface(
257-
{ input: fi, output: fi, terminal: terminal }
258-
);
259-
const expectedLines = ['foo', 'bar', 'baz', 'bat'];
260-
let callCount = 0;
261-
rli.on('line', function(line) {
262-
assert.strictEqual(line, expectedLines[callCount]);
263-
callCount++;
264-
});
265-
expectedLines.forEach(function(line) {
266-
fi.emit('data', `${line}\r`);
267-
fi.emit('data', '\n');
268-
});
269-
assert.strictEqual(callCount, expectedLines.length);
270-
rli.close();
271-
}
272-
273237
// \r should behave like \n when alone
274238
{
275239
const fi = new FakeInput();
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
// Flags: --expose_internals
23+
'use strict';
24+
require('../common');
25+
26+
// These test cases are in `sequential` rather than the analogous test file in
27+
// `parallel` because they become unrelaible under load. The unreliability under
28+
// load was determined empirically when the test cases were in `parallel` by
29+
// running:
30+
// tools/test.py -j 96 --repeat 192 test/parallel/test-readline-interface.js
31+
32+
const assert = require('assert');
33+
const readline = require('readline');
34+
const EventEmitter = require('events').EventEmitter;
35+
const inherits = require('util').inherits;
36+
37+
function FakeInput() {
38+
EventEmitter.call(this);
39+
}
40+
inherits(FakeInput, EventEmitter);
41+
FakeInput.prototype.resume = () => {};
42+
FakeInput.prototype.pause = () => {};
43+
FakeInput.prototype.write = () => {};
44+
FakeInput.prototype.end = () => {};
45+
46+
[ true, false ].forEach(function(terminal) {
47+
// sending multiple newlines at once that does not end with a new line
48+
// and a `end` event(last line is)
49+
50+
// \r\n should emit one line event, not two
51+
{
52+
const fi = new FakeInput();
53+
const rli = new readline.Interface(
54+
{ input: fi, output: fi, terminal: terminal }
55+
);
56+
const expectedLines = ['foo', 'bar', 'baz', 'bat'];
57+
let callCount = 0;
58+
rli.on('line', function(line) {
59+
assert.strictEqual(line, expectedLines[callCount]);
60+
callCount++;
61+
});
62+
fi.emit('data', expectedLines.join('\r\n'));
63+
assert.strictEqual(callCount, expectedLines.length - 1);
64+
rli.close();
65+
}
66+
67+
// \r\n should emit one line event when split across multiple writes.
68+
{
69+
const fi = new FakeInput();
70+
const rli = new readline.Interface(
71+
{ input: fi, output: fi, terminal: terminal }
72+
);
73+
const expectedLines = ['foo', 'bar', 'baz', 'bat'];
74+
let callCount = 0;
75+
rli.on('line', function(line) {
76+
assert.strictEqual(line, expectedLines[callCount]);
77+
callCount++;
78+
});
79+
expectedLines.forEach(function(line) {
80+
fi.emit('data', `${line}\r`);
81+
fi.emit('data', '\n');
82+
});
83+
assert.strictEqual(callCount, expectedLines.length);
84+
rli.close();
85+
}
86+
});

0 commit comments

Comments
 (0)