Skip to content

Commit 49ac083

Browse files
committed
tls: Add test for #1775
1 parent 3fc01d9 commit 49ac083

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

test/simple/test-tls-pause.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
if (!process.versions.openssl) {
23+
console.error('Skipping because node compiled without OpenSSL.');
24+
process.exit(0);
25+
}
26+
27+
var common = require('../common');
28+
var assert = require('assert');
29+
var tls = require('tls');
30+
var fs = require('fs');
31+
var path = require('path');
32+
33+
var options = {
34+
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
35+
cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))
36+
};
37+
38+
var bufSize = 1024 * 1024;
39+
var sent = 0;
40+
var received = 0;
41+
42+
var server = tls.Server(options, function(socket) {
43+
socket.pipe(socket);
44+
});
45+
46+
server.listen(common.PORT, function() {
47+
var resumed = false;
48+
var client = tls.connect(common.PORT, function() {
49+
client.pause();
50+
common.debug('paused');
51+
send();
52+
function send() {
53+
if (client.write(new Buffer(bufSize))) {
54+
sent += bufSize;
55+
assert.ok(sent < 100 * 1024 * 1024); // max 100MB
56+
return process.nextTick(send);
57+
}
58+
sent += bufSize;
59+
common.debug('sent: ' + sent);
60+
resumed = true;
61+
client.resume();
62+
common.debug('resumed');
63+
}
64+
});
65+
client.on('data', function(data) {
66+
assert.ok(resumed);
67+
received += data.length;
68+
if (received >= sent) {
69+
common.debug('received: ' + received);
70+
client.end();
71+
server.close();
72+
}
73+
});
74+
});
75+
76+
process.on('exit', function() {
77+
assert.equal(sent, received);
78+
});

0 commit comments

Comments
 (0)