mirror of https://github.com/grpc/grpc-node.git
Removed port_picker and bound to port 0 in tests instead
This commit is contained in:
parent
215e76570a
commit
6be3712bb4
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2014, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
var net = require('net');
|
||||
|
||||
/**
|
||||
* Finds a free port that a server can bind to, in the format
|
||||
* "address:port"
|
||||
* @param {function(string)} cb The callback that should execute when the port
|
||||
* is available
|
||||
*/
|
||||
function nextAvailablePort(cb) {
|
||||
var server = net.createServer();
|
||||
server.listen(function() {
|
||||
var address = server.address();
|
||||
server.close(function() {
|
||||
cb(address.address + ':' + address.port.toString());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.nextAvailablePort = nextAvailablePort;
|
|
@ -194,7 +194,7 @@ NAN_METHOD(Server::AddHttp2Port) {
|
|||
return NanThrowTypeError("addHttp2Port's argument must be a String");
|
||||
}
|
||||
Server *server = ObjectWrap::Unwrap<Server>(args.This());
|
||||
NanReturnValue(NanNew<Boolean>(grpc_server_add_http2_port(
|
||||
NanReturnValue(NanNew<Number>(grpc_server_add_http2_port(
|
||||
server->wrapped_server, *NanUtf8String(args[0]))));
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ NAN_METHOD(Server::AddSecureHttp2Port) {
|
|||
return NanThrowTypeError("addSecureHttp2Port's argument must be a String");
|
||||
}
|
||||
Server *server = ObjectWrap::Unwrap<Server>(args.This());
|
||||
NanReturnValue(NanNew<Boolean>(grpc_server_add_secure_http2_port(
|
||||
NanReturnValue(NanNew<Number>(grpc_server_add_secure_http2_port(
|
||||
server->wrapped_server, *NanUtf8String(args[0]))));
|
||||
}
|
||||
|
||||
|
|
|
@ -256,9 +256,9 @@ Server.prototype.register = function(name, handler) {
|
|||
*/
|
||||
Server.prototype.bind = function(port, secure) {
|
||||
if (secure) {
|
||||
this._server.addSecureHttp2Port(port);
|
||||
return this._server.addSecureHttp2Port(port);
|
||||
} else {
|
||||
this._server.addHttp2Port(port);
|
||||
return this._server.addHttp2Port(port);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -353,8 +353,7 @@ function makeServerConstructor(services) {
|
|||
* @return {SurfaceServer} this
|
||||
*/
|
||||
SurfaceServer.prototype.bind = function(port, secure) {
|
||||
this.inner_server.bind(port, secure);
|
||||
return this;
|
||||
return this.inner_server.bind(port, secure);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,6 @@ var path = require('path');
|
|||
var grpc = require('bindings')('grpc.node');
|
||||
var Server = require('../server');
|
||||
var client = require('../client');
|
||||
var port_picker = require('../port_picker');
|
||||
var common = require('../common');
|
||||
var _ = require('highland');
|
||||
|
||||
|
@ -80,14 +79,13 @@ function errorHandler(stream) {
|
|||
|
||||
describe('echo client', function() {
|
||||
it('should receive echo responses', function(done) {
|
||||
port_picker.nextAvailablePort(function(port) {
|
||||
var server = new Server();
|
||||
server.bind(port);
|
||||
var port_num = server.bind('0.0.0.0:0');
|
||||
server.register('echo', echoHandler);
|
||||
server.start();
|
||||
|
||||
var messages = ['echo1', 'echo2', 'echo3', 'echo4'];
|
||||
var channel = new grpc.Channel(port);
|
||||
var channel = new grpc.Channel('localhost:' + port_num);
|
||||
var stream = client.makeRequest(
|
||||
channel,
|
||||
'echo');
|
||||
|
@ -104,15 +102,13 @@ describe('echo client', function() {
|
|||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should get an error status that the server throws', function(done) {
|
||||
port_picker.nextAvailablePort(function(port) {
|
||||
var server = new Server();
|
||||
server.bind(port);
|
||||
var port_num = server.bind('0.0.0.0:0');
|
||||
server.register('error', errorHandler);
|
||||
server.start();
|
||||
|
||||
var channel = new grpc.Channel(port);
|
||||
var channel = new grpc.Channel('localhost:' + port_num);
|
||||
var stream = client.makeRequest(
|
||||
channel,
|
||||
'error',
|
||||
|
@ -128,15 +124,12 @@ describe('echo client', function() {
|
|||
server.shutdown();
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
/* TODO(mlumish): explore options for reducing duplication between this test
|
||||
* and the insecure echo client test */
|
||||
describe('secure echo client', function() {
|
||||
it('should recieve echo responses', function(done) {
|
||||
port_picker.nextAvailablePort(function(port) {
|
||||
fs.readFile(ca_path, function(err, ca_data) {
|
||||
assert.ifError(err);
|
||||
fs.readFile(key_path, function(err, key_data) {
|
||||
|
@ -149,12 +142,12 @@ describe('secure echo client', function() {
|
|||
pem_data);
|
||||
|
||||
var server = new Server({'credentials' : server_creds});
|
||||
server.bind(port, true);
|
||||
var port_num = server.bind('0.0.0.0:0', true);
|
||||
server.register('echo', echoHandler);
|
||||
server.start();
|
||||
|
||||
var messages = ['echo1', 'echo2', 'echo3', 'echo4'];
|
||||
var channel = new grpc.Channel(port, {
|
||||
var channel = new grpc.Channel('localhost:' + port_num, {
|
||||
'grpc.ssl_target_name_override' : 'foo.test.google.com',
|
||||
'credentials' : creds
|
||||
});
|
||||
|
@ -175,8 +168,6 @@ describe('secure echo client', function() {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
var assert = require('assert');
|
||||
var grpc = require('bindings')('grpc.node');
|
||||
var port_picker = require('../port_picker');
|
||||
|
||||
/**
|
||||
* This is used for testing functions with multiple asynchronous calls that
|
||||
|
@ -58,14 +57,13 @@ function multiDone(done, count) {
|
|||
|
||||
describe('end-to-end', function() {
|
||||
it('should start and end a request without error', function(complete) {
|
||||
port_picker.nextAvailablePort(function(port) {
|
||||
var server = new grpc.Server();
|
||||
var done = multiDone(function() {
|
||||
complete();
|
||||
server.shutdown();
|
||||
}, 2);
|
||||
server.addHttp2Port(port);
|
||||
var channel = new grpc.Channel(port);
|
||||
var port_num = server.addHttp2Port('0.0.0.0:0');
|
||||
var channel = new grpc.Channel('localhost:' + port_num);
|
||||
var deadline = new Date();
|
||||
deadline.setSeconds(deadline.getSeconds() + 3);
|
||||
var status_text = 'xyz';
|
||||
|
@ -112,10 +110,8 @@ describe('end-to-end', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should send and receive data without error', function(complete) {
|
||||
port_picker.nextAvailablePort(function(port) {
|
||||
var req_text = 'client_request';
|
||||
var reply_text = 'server_response';
|
||||
var server = new grpc.Server();
|
||||
|
@ -123,8 +119,8 @@ describe('end-to-end', function() {
|
|||
complete();
|
||||
server.shutdown();
|
||||
}, 6);
|
||||
server.addHttp2Port(port);
|
||||
var channel = new grpc.Channel(port);
|
||||
var port_num = server.addHttp2Port('0.0.0.0:0');
|
||||
var channel = new grpc.Channel('localhost:' + port_num);
|
||||
var deadline = new Date();
|
||||
deadline.setSeconds(deadline.getSeconds() + 3);
|
||||
var status_text = 'success';
|
||||
|
@ -197,5 +193,4 @@ describe('end-to-end', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
*/
|
||||
|
||||
var assert = require('assert');
|
||||
var port_picker = require('../port_picker');
|
||||
|
||||
var grpc = require('..');
|
||||
var math = grpc.load(__dirname + '/../examples/math.proto').math;
|
||||
|
@ -50,12 +49,11 @@ var server = require('../examples/math_server.js');
|
|||
|
||||
describe('Math client', function() {
|
||||
before(function(done) {
|
||||
port_picker.nextAvailablePort(function(port) {
|
||||
server.bind(port).listen();
|
||||
math_client = new math.Math(port);
|
||||
var port_num = server.bind('0.0.0.0:0');
|
||||
server.listen();
|
||||
math_client = new math.Math('localhost:' + port_num);
|
||||
done();
|
||||
});
|
||||
});
|
||||
after(function() {
|
||||
server.shutdown();
|
||||
});
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
var assert = require('assert');
|
||||
var grpc = require('bindings')('grpc.node');
|
||||
var Server = require('../server');
|
||||
var port_picker = require('../port_picker');
|
||||
|
||||
/**
|
||||
* This is used for testing functions with multiple asynchronous calls that
|
||||
|
@ -68,16 +67,15 @@ function echoHandler(stream) {
|
|||
describe('echo server', function() {
|
||||
it('should echo inputs as responses', function(done) {
|
||||
done = multiDone(done, 4);
|
||||
port_picker.nextAvailablePort(function(port) {
|
||||
var server = new Server();
|
||||
server.bind(port);
|
||||
var port_num = server.bind('[::]:0');
|
||||
server.register('echo', echoHandler);
|
||||
server.start();
|
||||
|
||||
var req_text = 'echo test string';
|
||||
var status_text = 'OK';
|
||||
|
||||
var channel = new grpc.Channel(port);
|
||||
var channel = new grpc.Channel('localhost:' + port_num);
|
||||
var deadline = new Date();
|
||||
deadline.setSeconds(deadline.getSeconds() + 3);
|
||||
var call = new grpc.Call(channel,
|
||||
|
@ -117,5 +115,4 @@ describe('echo server', function() {
|
|||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue