mirror of https://github.com/grpc/grpc-node.git
Add regression tests for recent failures, move a test
This commit is contained in:
parent
56df09ceb0
commit
ee0554231b
|
|
@ -0,0 +1,136 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2019 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const interopServer = require('../interop/interop_server.js');
|
||||||
|
const grpc = require('../any_grpc').client;
|
||||||
|
var protoLoader = require('../../packages/proto-loader');
|
||||||
|
|
||||||
|
const protoPackage = protoLoader.loadSync(
|
||||||
|
'src/proto/grpc/testing/test.proto',
|
||||||
|
{keepCase: true,
|
||||||
|
defaults: true,
|
||||||
|
enums: String,
|
||||||
|
includeDirs: [__dirname + '/../../packages/grpc-native-core/deps/grpc']});
|
||||||
|
const testProto = grpc.loadPackageDefinition(protoPackage).grpc.testing;
|
||||||
|
|
||||||
|
function multiDone(done, count) {
|
||||||
|
return function() {
|
||||||
|
count -= 1;
|
||||||
|
if (count <= 0) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function echoMetadataGenerator(options, callback) {
|
||||||
|
const metadata = new grpc.Metadata();
|
||||||
|
metadata.set('x-grpc-test-echo-initial', 'test_initial_metadata_value');
|
||||||
|
console.log('Adding metadata');
|
||||||
|
console.log(metadata);
|
||||||
|
callback(null, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
const credentials = grpc.credentials.createFromMetadataGenerator(echoMetadataGenerator);
|
||||||
|
|
||||||
|
describe('Interop-adjacent tests', function() {
|
||||||
|
let server;
|
||||||
|
let client;
|
||||||
|
before(function(done) {
|
||||||
|
interopServer.getServer(0, true, (err, serverObj) => {
|
||||||
|
if (err) {
|
||||||
|
done(err);
|
||||||
|
} else {
|
||||||
|
server = serverObj.server;
|
||||||
|
server.start();
|
||||||
|
const ca_path = path.join(__dirname, '../data/ca.pem');
|
||||||
|
const ca_data = fs.readFileSync(ca_path);
|
||||||
|
const creds = grpc.credentials.createSsl(ca_data);
|
||||||
|
const options = {
|
||||||
|
'grpc.ssl_target_name_override': 'foo.test.google.fr',
|
||||||
|
'grpc.default_authority': 'foo.test.google.fr'
|
||||||
|
};
|
||||||
|
client = new testProto.TestService(`localhost:${serverObj.port}`, creds, options);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
after(function() {
|
||||||
|
server.forceShutdown();
|
||||||
|
});
|
||||||
|
it('Should be able to start many concurrent calls', function(done) {
|
||||||
|
const callCount = 1000;
|
||||||
|
done = multiDone(done, callCount);
|
||||||
|
for (let i = 0; i < callCount; i++) {
|
||||||
|
client.unaryCall({}, (error, result) => {
|
||||||
|
assert.ifError(error);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('Should echo metadata from call credentials', function(done) {
|
||||||
|
done = multiDone(done, 2);
|
||||||
|
const call = client.unaryCall({}, {credentials}, (error, result) => {
|
||||||
|
assert.ifError(error);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
call.on('metadata', (metadata) => {
|
||||||
|
assert.deepEqual(metadata.get('x-grpc-test-echo-initial'),
|
||||||
|
['test_initial_metadata_value']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('Should be able to send the same metadata on two calls with call creds', function(done) {
|
||||||
|
done = multiDone(done, 5);
|
||||||
|
const metadata = new grpc.Metadata();
|
||||||
|
metadata.set('x-grpc-test-echo-trailing-bin', Buffer.from('ababab', 'hex'));
|
||||||
|
const call1 = client.unaryCall({}, metadata, {credentials}, (error, result) => {
|
||||||
|
assert.ifError(error);
|
||||||
|
const call2 = client.unaryCall({}, metadata, {credentials}, (error, result) => {
|
||||||
|
assert.ifError(error);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
call2.on('metadata', (metadata) => {
|
||||||
|
assert.deepEqual(metadata.get('x-grpc-test-echo-initial'),
|
||||||
|
['test_initial_metadata_value']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
call2.on('status', function(status) {
|
||||||
|
var echo_trailer = status.metadata.get('x-grpc-test-echo-trailing-bin');
|
||||||
|
assert(echo_trailer.length === 1);
|
||||||
|
assert.strictEqual(echo_trailer[0].toString('hex'), 'ababab');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
call1.on('metadata', (metadata) => {
|
||||||
|
assert.deepEqual(metadata.get('x-grpc-test-echo-initial'),
|
||||||
|
['test_initial_metadata_value']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
call1.on('status', function(status) {
|
||||||
|
var echo_trailer = status.metadata.get('x-grpc-test-echo-trailing-bin');
|
||||||
|
assert(echo_trailer.length === 1);
|
||||||
|
assert.strictEqual(echo_trailer[0].toString('hex'), 'ababab');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019 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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
keepCase: true,
|
|
||||||
longs: String,
|
|
||||||
enums: String,
|
|
||||||
defaults: true,
|
|
||||||
oneofs: true
|
|
||||||
};
|
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
const assert = require('assert');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const anyGrpc = require('../any_grpc');
|
|
||||||
const clientGrpc = anyGrpc.client;
|
|
||||||
const serverGrpc = anyGrpc.server;
|
|
||||||
const protoLoader = require('../../packages/proto-loader', options);
|
|
||||||
const testServiceDef = protoLoader.loadSync(__dirname + '/../proto/test_service.proto');
|
|
||||||
const TestService = serverGrpc.loadPackageDefinition(testServiceDef).TestService.service;
|
|
||||||
const TestServiceClient = clientGrpc.loadPackageDefinition(testServiceDef).TestService;
|
|
||||||
|
|
||||||
const keyPath = path.join(__dirname, '../data/server1.key');
|
|
||||||
const pemPath = path.join(__dirname, '../data/server1.pem');
|
|
||||||
const caPath = path.join(__dirname, '../data/ca.pem');
|
|
||||||
const keyData = fs.readFileSync(keyPath);
|
|
||||||
const pemData = fs.readFileSync(pemPath);
|
|
||||||
const caData = fs.readFileSync(caPath);
|
|
||||||
|
|
||||||
const clientCreds = clientGrpc.credentials.createSsl(caData);
|
|
||||||
const dummyCallCreds = clientGrpc.credentials.createFromMetadataGenerator((options, callback) => {
|
|
||||||
const metadata = new clientGrpc.Metadata();
|
|
||||||
metadata.add('authorization', 'test');
|
|
||||||
callback(null, metadata);
|
|
||||||
});
|
|
||||||
const combinedClientCreds = clientGrpc.credentials.combineChannelCredentials(clientCreds, dummyCallCreds);
|
|
||||||
const serverCreds = serverGrpc.ServerCredentials.createSsl(null, [{private_key: keyData, cert_chain: pemData}]);
|
|
||||||
|
|
||||||
const hostOverride = 'foo.test.google.fr';
|
|
||||||
const clientOptions = {
|
|
||||||
'grpc.ssl_target_name_override': hostOverride,
|
|
||||||
'grpc.default_authority': hostOverride
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Sending metadata', function() {
|
|
||||||
let server;
|
|
||||||
before(function(done) {
|
|
||||||
server = new serverGrpc.Server();
|
|
||||||
server.addService(TestService, {
|
|
||||||
unary: function(call, cb) {
|
|
||||||
cb(null, {});
|
|
||||||
},
|
|
||||||
clientStream: function(stream, cb){
|
|
||||||
stream.on('data', function(data) {});
|
|
||||||
stream.on('end', function() {
|
|
||||||
cb(null, {});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
serverStream: function(stream) {
|
|
||||||
stream.end();
|
|
||||||
},
|
|
||||||
bidiStream: function(stream) {
|
|
||||||
stream.on('data', function(data) {});
|
|
||||||
stream.on('end', function() {
|
|
||||||
stream.end();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
server.bindAsync('localhost:0', serverCreds, (err, port) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
server.start();
|
|
||||||
client = new TestServiceClient(`localhost:${port}`, combinedClientCreds, clientOptions);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
after(function() {
|
|
||||||
server.forceShutdown();
|
|
||||||
});
|
|
||||||
it('Should be able to send the same metadata on two calls with call creds', function(done) {
|
|
||||||
const metadata = new clientGrpc.Metadata();
|
|
||||||
client.unary({}, metadata, (err, data) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
client.unary({}, metadata, (err, data) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Loading…
Reference in New Issue