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. 78
      src/node/test/client_server_test.js

@ -34,8 +34,6 @@
var assert = require('assert');
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
* seconds.
@ -49,6 +47,17 @@ function getDeadline(timeout_secs) {
}
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() {
it('should reject anything less than 3 arguments', function() {
assert.throws(function() {

@ -86,14 +86,23 @@ function cancelHandler(stream) {
}
describe('echo client', function() {
it('should receive echo responses', function(done) {
var server = new Server();
var server;
var channel;
before(function() {
server = new Server();
var port_num = server.bind('0.0.0.0:0');
server.register('echo', echoHandler);
server.register('error', errorHandler);
server.register('cancellation', cancelHandler);
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 channel = new grpc.Channel('localhost:' + port_num);
var stream = client.makeRequest(
channel,
'echo');
@ -106,17 +115,10 @@ describe('echo client', function() {
index += 1;
});
stream.on('end', function() {
server.shutdown();
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(
channel,
'error',
@ -129,17 +131,10 @@ describe('echo client', function() {
stream.on('status', function(status) {
assert.equal(status.code, grpc.status.UNIMPLEMENTED);
assert.equal(status.details, 'error details');
server.shutdown();
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(
channel,
'cancellation',
@ -149,7 +144,6 @@ describe('echo client', function() {
stream.cancel();
stream.on('status', function(status) {
assert.equal(status.code, grpc.status.CANCELLED);
server.shutdown();
done();
});
});
@ -157,7 +151,9 @@ describe('echo client', function() {
/* 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) {
var server;
var channel;
before(function(done) {
fs.readFile(ca_path, function(err, ca_data) {
assert.ifError(err);
fs.readFile(key_path, function(err, key_data) {
@ -169,34 +165,40 @@ describe('secure echo client', function() {
key_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);
server.register('echo', echoHandler);
server.start();
var messages = ['echo1', 'echo2', 'echo3', 'echo4'];
var channel = new grpc.Channel('localhost:' + port_num, {
channel = new grpc.Channel('localhost:' + port_num, {
'grpc.ssl_target_name_override' : 'foo.test.google.com',
'credentials' : creds
});
var stream = client.makeRequest(
channel,
'echo');
_(messages).map(function(val) {
return new Buffer(val);
}).pipe(stream);
var index = 0;
stream.on('data', function(chunk) {
assert.equal(messages[index], chunk.toString());
index += 1;
});
stream.on('end', function() {
server.shutdown();
done();
});
done();
});
});
});
});
after(function() {
server.shutdown();
});
it('should recieve echo responses', function(done) {
var messages = ['echo1', 'echo2', 'echo3', 'echo4'];
var stream = client.makeRequest(
channel,
'echo');
_(messages).map(function(val) {
return new Buffer(val);
}).pipe(stream);
var index = 0;
stream.on('data', function(chunk) {
assert.equal(messages[index], chunk.toString());
index += 1;
});
stream.on('end', function() {
server.shutdown();
done();
});
});
});

Loading…
Cancel
Save