Skip to content

Commit 3f53b9b

Browse files
Daniel Ballayichoi
authored andcommitted
Cover a few missing functions (#956)
Covering some of the missing public functions, migrating parallel/test-net-keepalive.js. IoT.js-DCO-1.0-Signed-off-by: Daniel Balla [email protected]
1 parent c82a3d3 commit 3f53b9b

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
// Copyright Joyent, Inc. and other Node contributors.
17+
//
18+
// Permission is hereby granted, free of charge, to any person obtaining a
19+
// copy of this software and associated documentation files (the
20+
// "Software"), to deal in the Software without restriction, including
21+
// without limitation the rights to use, copy, modify, merge, publish,
22+
// distribute, sublicense, and/or sell copies of the Software, and to permit
23+
// persons to whom the Software is furnished to do so, subject to the
24+
// following conditions:
25+
//
26+
// The above copyright notice and this permission notice shall be included
27+
// in all copies or substantial portions of the Software.
28+
//
29+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
32+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
33+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
34+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
35+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
36+
37+
'use strict';
38+
39+
var common = require('node/common');
40+
var assert = require('assert');
41+
var net = require('net');
42+
43+
var serverConnection;
44+
var clientConnection;
45+
var echoServer = net.createServer(function(connection) {
46+
serverConnection = connection;
47+
setTimeout(function() {
48+
serverConnection.end();
49+
clientConnection.end();
50+
echoServer.close();
51+
}, 100);
52+
connection.setTimeout(0);
53+
assert.notStrictEqual(connection.setKeepAlive, undefined);
54+
// send a keepalive packet after 50 ms
55+
connection.setKeepAlive(true, 50);
56+
connection.on('end', function() {
57+
connection.end();
58+
});
59+
});
60+
echoServer.listen(0);
61+
62+
echoServer.on('listening', function() {
63+
clientConnection = net.createConnection(this.address().port);
64+
clientConnection.setTimeout(0);
65+
});

test/run_pass/test_net_httpclient_timeout_1.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
var assert = require('assert');
1919
var http = require('http');
20+
var IncomingMessage = require('http_incoming').IncomingMessage;
21+
var OutgoingMessage = require('http_outgoing').OutgoingMessage;
22+
var net = require('net');
2023

2124
var timeouted = false;
2225

@@ -25,6 +28,20 @@ var options = {
2528
port: 3002
2629
};
2730

31+
var incTimeout = 0;
32+
var outTimeout = 0;
33+
34+
var socket = new net.Socket();
35+
var inc = new IncomingMessage(socket);
36+
inc.setTimeout(100, function() {
37+
incTimeout++;
38+
});
39+
var out = new OutgoingMessage();
40+
out.setTimeout(100, function() {
41+
outTimeout++;
42+
});
43+
out.emit('timeout');
44+
2845
var server = http.createServer(function(req, res) {
2946
// do nothing
3047
});
@@ -48,4 +65,6 @@ server.listen(options.port, function() {
4865
process.on('exit', function(code) {
4966
assert.equal(code,0);
5067
assert.equal(timeouted, true);
68+
assert.equal(incTimeout, 1);
69+
assert.equal(outTimeout, 1);
5170
});

test/testsets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
{ "name": "test-assert.js" },
116116
{ "name": "test-http-write-head.js" },
117117
{ "name": "test-net-bind-twice.js" },
118-
{ "name": "test-net-end-without-connect.js" }
118+
{ "name": "test-net-end-without-connect.js" },
119+
{ "name": "test-net-keepalive.js"}
119120
]
120121
}

0 commit comments

Comments
 (0)