Get tests from the C-based library working and add corresponding gulp tasks

This commit is contained in:
murgatroid99 2017-09-13 13:54:13 -07:00
parent ec5492d25f
commit 0fe5704ad7
28 changed files with 157 additions and 85 deletions

4
.gitignore vendored
View File

@ -6,4 +6,6 @@ npm-debug.log
yarn-error.log
yarn.lock
*~
*~
packages/grpc-native-core/src/node/

View File

@ -6,16 +6,25 @@ const gulp = help(_gulp);
require('./packages/grpc-health-check/gulpfile');
require('./packages/grpc-js-core/gulpfile');
require('./packages/grpc-native-core/gulpfile');
require('./test/gulpfile');
gulp.task('lint', 'Emit linting errors in source and test files', ['js.core.lint']);
gulp.task('lint', 'Emit linting errors in source and test files',
['js.core.lint', 'native.core.lint']);
gulp.task('link', 'Link local packages together', ['internal.test.link']);
gulp.task('link', 'Link local packages together',
['health-check.link', 'internal.test.link']);
gulp.task('build', 'Build packages', ['js.core.compile', 'link']);
gulp.task('build', 'Build packages',
['js.core.compile', 'native.core.build', 'link']);
gulp.task('clean', 'Delete generated files', ['js.core.clean']);
gulp.task('test', 'Run all tests', ['js.core.test']);
gulp.task('test.only', 'Run tests without rebuilding anything',
['js.core.test', 'native.core.test', 'internal.test.test', 'health-check.test']);
gulp.task('test', 'Run all tests', ['build', 'link'], () => {
gulp.start('test.only');
});
gulp.task('default', ['help']);

View File

@ -16,7 +16,6 @@
"grpc": "^1.6.0",
"gulp": "^3.9.1",
"gulp-help": "^1.6.1",
"gulp-run": "^1.7.1",
"lodash": "^4.17.4",
"poisson-process": "^0.2.2"
},
@ -27,5 +26,9 @@
{
"name": "Google Inc."
}
]
],
"dependencies": {
"gulp-mocha": "^4.3.1",
"mocha": "^3.5.3"
}
}

View File

@ -1,10 +1,20 @@
const _gulp = require('gulp');
const help = require('gulp-help');
const run = require('gulp-run');
const mocha = require('gulp-mocha');
const exec = require('child_process').exec;
const path = require('path');
const gulp = help(_gulp);
gulp.task('health-check.link', 'Link local copy of grpc', () => {
return run(`npm link ${__dirname}/grpc-native-core`).exec()
.pipe(gulp.dest('output'));
const hcCoreDir = __dirname;
const baseDir = path.resolve(hcCoreDir, '..', '..');
const testDir = path.resolve(hcCoreDir, 'test');
gulp.task('health-check.link', 'Link local copy of grpc', (cb) => {
return exec(`cd ${hcCoreDir} && npm link ${baseDir}/packages/grpc-native-core`, cb);
});
gulp.task('health-check.test', 'Run health check tests', ['health-check.link'],
() => {
return gulp.src(`${testDir}/*.js`).pipe(mocha());
});

View File

@ -16,7 +16,7 @@
],
"dependencies": {
"google-protobuf": "^3.0.0",
"grpc": "^1.7.0-dev",
"grpc": "^1.6.0",
"lodash": "^3.9.3"
},
"files": [

View File

@ -20,13 +20,13 @@
var assert = require('assert');
var health = require('../health_check/health');
var health = require('../health');
var health_messages = require('../health_check/v1/health_pb');
var health_messages = require('../v1/health_pb');
var ServingStatus = health_messages.HealthCheckResponse.ServingStatus;
var grpc = require('../');
var grpc = require('grpc');
describe('Health Checking', function() {
var statusMap = {

View File

@ -20,14 +20,11 @@
"clang-format": "^1.0.53",
"del": "^3.0.0",
"google-ts-style": "^0.2.0",
"gulp-help": "^1.6.1",
"gulp-mocha": "^4.3.1",
"gulp-sourcemaps": "^2.6.1",
"gulp-tslint": "^8.1.1",
"gulp-typescript": "^3.2.2",
"gulp-util": "^3.0.8",
"merge2": "^1.1.0",
"mocha": "^3.5.0",
"through2": "^2.0.3",
"tslint": "^5.5.0",
"typescript": "^2.5.1"

View File

@ -0,0 +1,31 @@
const _gulp = require('gulp');
const help = require('gulp-help');
// gulp-help monkeypatches tasks to have an additional description parameter
const gulp = help(_gulp);
const jshint = require('gulp-jshint');
const mocha = require('gulp-mocha');
const exec = require('child_process').exec;
const path = require('path');
const nativeCoreDir = __dirname;
const srcDir = path.resolve(nativeCoreDir, 'src');
const testDir = path.resolve(nativeCoreDir, 'test');
const pkg = require('./package');
const jshintConfig = pkg.jshintConfig;
gulp.task('native.core.lint', 'Emits linting errors', () => {
return gulp.src([`${nativeCoreDir}/index.js`, `${srcDir}/*.js`, `${testDir}/*.js`])
.pipe(jshint(pkg.jshintConfig))
.pipe(jshint.reporter('default'));
});
gulp.task('native.core.build', 'Build native package', (cb) => {
return exec(`cd ${nativeCoreDir} && ${nativeCoreDir}/node_modules/.bin/node-pre-gyp build`, cb);
});
gulp.task('native.core.test', 'Run all tests', ['native.core.build'], () => {
return gulp.src(`${testDir}/*.js`).pipe(mocha());
});

View File

@ -21,7 +21,7 @@
var path = require('path');
var fs = require('fs');
var SSL_ROOTS_PATH = path.resolve(__dirname, '..', '..', 'etc', 'roots.pem');
var SSL_ROOTS_PATH = path.resolve(__dirname, 'deps', 'grpc', 'etc', 'roots.pem');
var _ = require('lodash');

View File

@ -31,6 +31,7 @@
],
"dependencies": {
"arguejs": "^0.2.3",
"gulp-jshint": "^2.0.4",
"lodash": "^4.15.0",
"nan": "^2.0.0",
"node-pre-gyp": "^0.6.35",
@ -47,7 +48,6 @@
"jsdoc": "^3.3.2",
"jshint": "^2.5.0",
"minimist": "^1.1.0",
"mocha": "^3.0.2",
"mocha-jenkins-reporter": "^0.2.3",
"poisson-process": "^0.2.1"
},

View File

@ -51,7 +51,7 @@ var Readable = stream.Readable;
var Writable = stream.Writable;
var Duplex = stream.Duplex;
var util = require('util');
var version = require('../../../package.json').version;
var version = require('../package.json').version;
/**
* Initial response metadata sent by the server when it starts processing the

View File

@ -26,7 +26,7 @@
var binary = require('node-pre-gyp/lib/pre-binding');
var path = require('path');
var binding_path =
binary.find(path.resolve(path.join(__dirname, '../../../package.json')));
binary.find(path.resolve(path.join(__dirname, '../package.json')));
var binding = require(binding_path);
module.exports = binding;

View File

@ -21,7 +21,7 @@
var assert = require('assert');
var grpc = require('..');
var math = grpc.load(__dirname + '/../../proto/math/math.proto').math;
var math = grpc.load(__dirname + '/../deps/grpc/src/proto/math/math.proto').math;
/**

View File

@ -72,8 +72,8 @@ describe('server', function() {
});
it('should bind to an unused port with ssl credentials', function() {
var port;
var key_path = path.join(__dirname, '../test/data/server1.key');
var pem_path = path.join(__dirname, '../test/data/server1.pem');
var key_path = path.join(__dirname, '../../../test/data/server1.key');
var pem_path = path.join(__dirname, '../../../test/data/server1.pem');
var key_data = fs.readFileSync(key_path);
var pem_data = fs.readFileSync(pem_path);
var creds = grpc.ServerCredentials.createSsl(null,

View File

@ -22,7 +22,7 @@ var assert = require('assert');
var fs = require('fs');
var path = require('path');
var grpc = require('..');
var grpc = require('grpc');
/**
* This is used for testing functions with multiple asynchronous calls that
@ -67,9 +67,9 @@ var fakeFailingGoogleCredentials = {
var key_data, pem_data, ca_data;
before(function() {
var key_path = path.join(__dirname, './data/server1.key');
var pem_path = path.join(__dirname, './data/server1.pem');
var ca_path = path.join(__dirname, '../test/data/ca.pem');
var key_path = path.join(__dirname, '../data/server1.key');
var pem_path = path.join(__dirname, '../data/server1.pem');
var ca_path = path.join(__dirname, '../data/ca.pem');
key_data = fs.readFileSync(key_path);
pem_data = fs.readFileSync(pem_path);
ca_data = fs.readFileSync(ca_path);

View File

@ -21,19 +21,13 @@
var assert = require('assert');
var _ = require('lodash');
var surface_client = require('../src/client.js');
var common = require('../src/common');
var ProtoBuf = require('protobufjs');
var grpc = require('..');
var grpc = require('grpc');
var math_proto = ProtoBuf.loadProtoFile(__dirname +
'/../../proto/math/math.proto');
var mathService = math_proto.lookup('math.Math');
var mathServiceAttrs = grpc.loadObject(
mathService, common.defaultGrpcOptions).service;
var MathClient = grpc.load(
__dirname + '/../../packages/grpc-native-core/deps/grpc/src/proto/math/math.proto').math.Math;
var mathServiceAttrs = MathClient.service;
/**
* This is used for testing functions with multiple asynchronous calls that
@ -100,31 +94,6 @@ describe('surface Server', function() {
server.tryShutdown(done);
});
});
describe('Server.prototype.addProtoService', function() {
var server;
var dummyImpls = {
'div': function() {},
'divMany': function() {},
'fib': function() {},
'sum': function() {}
};
beforeEach(function() {
server = new grpc.Server();
});
afterEach(function() {
server.forceShutdown();
});
it('Should succeed with a single proto service', function() {
assert.doesNotThrow(function() {
server.addProtoService(mathService, dummyImpls);
});
});
it('Should succeed with a single service attributes object', function() {
assert.doesNotThrow(function() {
server.addProtoService(mathServiceAttrs, dummyImpls);
});
});
});
describe('Server.prototype.addService', function() {
var server;
var dummyImpls = {
@ -158,7 +127,7 @@ describe('Server.prototype.addService', function() {
'Sum': function() {}
};
assert.doesNotThrow(function() {
server.addProtoService(mathService, altDummyImpls);
server.addService(mathServiceAttrs, altDummyImpls);
});
});
it('Should have a conflict between name variations', function() {
@ -171,9 +140,9 @@ describe('Server.prototype.addService', function() {
'Fib': function() {},
'Sum': function() {}
};
server.addProtoService(mathService, altDummyImpls);
server.addProtoService(mathServiceAttrs, altDummyImpls);
assert.throws(function() {
server.addProtoService(mathService, dummyImpls);
server.addProtoService(mathServiceAttrs, dummyImpls);
});
});
it('Should fail if the server has been started', function() {
@ -187,9 +156,8 @@ describe('Server.prototype.addService', function() {
beforeEach(function() {
server.addService(mathServiceAttrs, {});
var port = server.bind('localhost:0', server_insecure_creds);
var Client = grpc.loadObject(mathService);
client = new Client('localhost:' + port,
grpc.credentials.createInsecure());
client = new MathClient('localhost:' + port,
grpc.credentials.createInsecure());
server.start();
});
it('should respond to a unary call with UNIMPLEMENTED', function(done) {
@ -253,13 +221,12 @@ describe('Client constructor building', function() {
describe('waitForClientReady', function() {
var server;
var port;
var Client;
var Client = MathClient;
var client;
before(function() {
server = new grpc.Server();
port = server.bind('localhost:0', grpc.ServerCredentials.createInsecure());
server.start();
Client = grpc.loadObject(mathService);
});
beforeEach(function() {
client = new Client('localhost:' + port, grpc.credentials.createInsecure());
@ -520,7 +487,7 @@ describe('Echo metadata', function() {
call.end();
});
it('shows the correct user-agent string', function(done) {
var version = require('../../../package.json').version;
var version = require('grpc/package.json').version;
var call = client.unary({}, metadata,
function(err, data) { assert.ifError(err); });
call.on('metadata', function(metadata) {
@ -887,8 +854,8 @@ describe('Other conditions', function() {
responseDeserialize: _.identity
}
};
var Client = surface_client.makeClientConstructor(test_service_attrs,
'TestService');
var Client = grpc.makeGenericClientConstructor(test_service_attrs,
'TestService');
misbehavingClient = new Client('localhost:' + port,
grpc.credentials.createInsecure());
});
@ -1310,7 +1277,7 @@ describe('Cancelling surface client', function() {
'sum': function(stream) {}
});
var port = server.bind('localhost:0', server_insecure_creds);
var Client = surface_client.makeClientConstructor(mathServiceAttrs);
var Client = grpc.makeGenericClientConstructor(mathServiceAttrs);
client = new Client('localhost:' + port, grpc.credentials.createInsecure());
server.start();
});

View File

@ -0,0 +1,45 @@
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
message LongValues {
int64 int_64 = 1;
uint64 uint_64 = 2;
sint64 sint_64 = 3;
fixed64 fixed_64 = 4;
sfixed64 sfixed_64 = 5;
}
message SequenceValues {
bytes bytes_field = 1;
repeated int32 repeated_field = 2;
}
message OneOfValues {
oneof oneof_choice {
int32 int_choice = 1;
string string_choice = 2;
}
}
enum TestEnum {
ZERO = 0;
ONE = 1;
TWO = 2;
}
message EnumValues {
TestEnum enum_value = 1;
}

View File

@ -1,11 +1,19 @@
const _gulp = require('gulp');
const help = require('gulp-help');
const run = require('gulp-run');
const mocha = require('gulp-mocha');
const exec = require('child_process').exec;
const path = require('path');
// gulp-help monkeypatches tasks to have an additional description parameter
const gulp = help(_gulp);
gulp.task('internal.test.link', 'Link local copies of grpc packages', () => {
return run(`npm link ${__dirname}/../packages/grpc-native-core`).exec()
.pipe(gulp.dest('output'));
const testDir = __dirname;
const apiTestDir = path.resolve(testDir, 'api');
gulp.task('internal.test.link', 'Link local copies of grpc packages', (cb) => {
return exec(`npm link ${testDir}/../packages/grpc-native-core`, cb);
});
gulp.task('internal.test.test', 'Run API-level tests', ['internal.test.link'], () => {
return gulp.src(`${apiTestDir}/*.js`).pipe(mocha());
});

View File

@ -23,7 +23,7 @@ var path = require('path');
// TODO(murgatroid99): use multiple grpc implementations
var grpc = require('grpc');
var testProto = grpc.load({
root: __dirname + '/../packages/grpc-native-core/ext/grpc',
root: __dirname + '/../../packages/grpc-native-core/deps/grpc',
file: 'src/proto/grpc/testing/test.proto'}).grpc.testing;
var GoogleAuth = require('google-auth-library');
@ -566,7 +566,7 @@ function runTest(address, host_override, test_case, tls, test_ca, done, extra) {
if (tls) {
var ca_path;
if (test_ca) {
ca_path = path.join(__dirname, '../test/data/ca.pem');
ca_path = path.join(__dirname, '../data/ca.pem');
var ca_data = fs.readFileSync(ca_path);
creds = grpc.credentials.createSsl(ca_data);
} else {

View File

@ -25,7 +25,7 @@ var AsyncDelayQueue = require('./async_delay_queue');
// TODO(murgatroid99): use multiple grpc implementations
var grpc = require('grpc');
var testProto = grpc.load({
root: __dirname + '/../packages/grpc-native-core/ext/grpc',
root: __dirname + '/../../packages/grpc-native-core/deps/grpc',
file: 'src/proto/grpc/testing/test.proto'}).grpc.testing;
var ECHO_INITIAL_KEY = 'x-grpc-test-echo-initial';
@ -202,8 +202,8 @@ function getServer(port, tls) {
var options = {};
var server_creds;
if (tls) {
var key_path = path.join(__dirname, '../test/data/server1.key');
var pem_path = path.join(__dirname, '../test/data/server1.pem');
var key_path = path.join(__dirname, '../data/server1.key');
var pem_path = path.join(__dirname, '../data/server1.pem');
var key_data = fs.readFileSync(key_path);
var pem_data = fs.readFileSync(pem_path);