Refactored tests to avoid hanging

pull/224/head
murgatroid99 10 years ago
parent 12958f9f25
commit 4b962f72d3
  1. 13
      src/node/test/call_test.js
  2. 52
      src/node/test/client_server_test.js

@ -34,8 +34,6 @@
var assert = require('assert'); var assert = require('assert');
var grpc = require('bindings')('grpc.node'); var grpc = require('bindings')('grpc.node');
var channel = new grpc.Channel('localhost:7070');
/** /**
* Helper function to return an absolute deadline given a relative timeout in * Helper function to return an absolute deadline given a relative timeout in
* seconds. * seconds.
@ -49,6 +47,17 @@ function getDeadline(timeout_secs) {
} }
describe('call', function() { describe('call', function() {
var channel;
var server;
before(function() {
server = new grpc.Server();
var port = server.addHttp2Port('localhost:0');
server.start();
channel = new grpc.Channel('localhost:' + port);
});
after(function() {
server.shutdown();
});
describe('constructor', function() { describe('constructor', function() {
it('should reject anything less than 3 arguments', function() { it('should reject anything less than 3 arguments', function() {
assert.throws(function() { assert.throws(function() {

@ -86,14 +86,23 @@ function cancelHandler(stream) {
} }
describe('echo client', function() { describe('echo client', function() {
it('should receive echo responses', function(done) { var server;
var server = new Server(); var channel;
before(function() {
server = new Server();
var port_num = server.bind('0.0.0.0:0'); var port_num = server.bind('0.0.0.0:0');
server.register('echo', echoHandler); server.register('echo', echoHandler);
server.register('error', errorHandler);
server.register('cancellation', cancelHandler);
server.start(); server.start();
channel = new grpc.Channel('localhost:' + port_num);
});
after(function() {
server.shutdown();
});
it('should receive echo responses', function(done) {
var messages = ['echo1', 'echo2', 'echo3', 'echo4']; var messages = ['echo1', 'echo2', 'echo3', 'echo4'];
var channel = new grpc.Channel('localhost:' + port_num);
var stream = client.makeRequest( var stream = client.makeRequest(
channel, channel,
'echo'); 'echo');
@ -106,17 +115,10 @@ describe('echo client', function() {
index += 1; index += 1;
}); });
stream.on('end', function() { stream.on('end', function() {
server.shutdown();
done(); done();
}); });
}); });
it('should get an error status that the server throws', function(done) { it('should get an error status that the server throws', function(done) {
var server = new Server();
var port_num = server.bind('0.0.0.0:0');
server.register('error', errorHandler);
server.start();
var channel = new grpc.Channel('localhost:' + port_num);
var stream = client.makeRequest( var stream = client.makeRequest(
channel, channel,
'error', 'error',
@ -129,17 +131,10 @@ describe('echo client', function() {
stream.on('status', function(status) { stream.on('status', function(status) {
assert.equal(status.code, grpc.status.UNIMPLEMENTED); assert.equal(status.code, grpc.status.UNIMPLEMENTED);
assert.equal(status.details, 'error details'); assert.equal(status.details, 'error details');
server.shutdown();
done(); done();
}); });
}); });
it('should be able to cancel a call', function(done) { it('should be able to cancel a call', function(done) {
var server = new Server();
var port_num = server.bind('0.0.0.0:0');
server.register('cancellation', cancelHandler);
server.start();
var channel = new grpc.Channel('localhost:' + port_num);
var stream = client.makeRequest( var stream = client.makeRequest(
channel, channel,
'cancellation', 'cancellation',
@ -149,7 +144,6 @@ describe('echo client', function() {
stream.cancel(); stream.cancel();
stream.on('status', function(status) { stream.on('status', function(status) {
assert.equal(status.code, grpc.status.CANCELLED); assert.equal(status.code, grpc.status.CANCELLED);
server.shutdown();
done(); done();
}); });
}); });
@ -157,7 +151,9 @@ describe('echo client', function() {
/* TODO(mlumish): explore options for reducing duplication between this test /* TODO(mlumish): explore options for reducing duplication between this test
* and the insecure echo client test */ * and the insecure echo client test */
describe('secure echo client', function() { describe('secure echo client', function() {
it('should recieve echo responses', function(done) { var server;
var channel;
before(function(done) {
fs.readFile(ca_path, function(err, ca_data) { fs.readFile(ca_path, function(err, ca_data) {
assert.ifError(err); assert.ifError(err);
fs.readFile(key_path, function(err, key_data) { fs.readFile(key_path, function(err, key_data) {
@ -169,16 +165,25 @@ describe('secure echo client', function() {
key_data, key_data,
pem_data); pem_data);
var server = new Server({'credentials' : server_creds}); server = new Server({'credentials' : server_creds});
var port_num = server.bind('0.0.0.0:0', true); var port_num = server.bind('0.0.0.0:0', true);
server.register('echo', echoHandler); server.register('echo', echoHandler);
server.start(); server.start();
var messages = ['echo1', 'echo2', 'echo3', 'echo4']; channel = new grpc.Channel('localhost:' + port_num, {
var channel = new grpc.Channel('localhost:' + port_num, {
'grpc.ssl_target_name_override' : 'foo.test.google.com', 'grpc.ssl_target_name_override' : 'foo.test.google.com',
'credentials' : creds 'credentials' : creds
}); });
done();
});
});
});
});
after(function() {
server.shutdown();
});
it('should recieve echo responses', function(done) {
var messages = ['echo1', 'echo2', 'echo3', 'echo4'];
var stream = client.makeRequest( var stream = client.makeRequest(
channel, channel,
'echo'); 'echo');
@ -196,7 +201,4 @@ describe('secure echo client', function() {
done(); done();
}); });
}); });
});
});
});
}); });

Loading…
Cancel
Save