mirror of https://github.com/grpc/grpc.git
commit
3a0b8477c2
173 changed files with 3403 additions and 925 deletions
@ -1,5 +1,5 @@ |
||||
{ |
||||
"sdk": { |
||||
"version": "1.0.0-preview2-003121" |
||||
"version": "1.0.0-preview2-003131" |
||||
} |
||||
} |
@ -0,0 +1,181 @@ |
||||
/* |
||||
* |
||||
* Copyright 2017, 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. |
||||
* |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
var _ = require('lodash'); |
||||
var client = require('./client'); |
||||
|
||||
/** |
||||
* Get a function that deserializes a specific type of protobuf. |
||||
* @param {function()} cls The constructor of the message type to deserialize |
||||
* @param {bool=} binaryAsBase64 Deserialize bytes fields as base64 strings |
||||
* instead of Buffers. Defaults to false |
||||
* @param {bool=} longsAsStrings Deserialize long values as strings instead of |
||||
* objects. Defaults to true |
||||
* @return {function(Buffer):cls} The deserialization function |
||||
*/ |
||||
exports.deserializeCls = function deserializeCls(cls, binaryAsBase64, |
||||
longsAsStrings) { |
||||
/** |
||||
* Deserialize a buffer to a message object |
||||
* @param {Buffer} arg_buf The buffer to deserialize |
||||
* @return {cls} The resulting object |
||||
*/ |
||||
return function deserialize(arg_buf) { |
||||
// Convert to a native object with binary fields as Buffers (first argument)
|
||||
// and longs as strings (second argument)
|
||||
return cls.decode(arg_buf).toRaw(binaryAsBase64, longsAsStrings); |
||||
}; |
||||
}; |
||||
|
||||
var deserializeCls = exports.deserializeCls; |
||||
|
||||
/** |
||||
* Get a function that serializes objects to a buffer by protobuf class. |
||||
* @param {function()} Cls The constructor of the message type to serialize |
||||
* @return {function(Cls):Buffer} The serialization function |
||||
*/ |
||||
exports.serializeCls = function serializeCls(Cls) { |
||||
/** |
||||
* Serialize an object to a Buffer |
||||
* @param {Object} arg The object to serialize |
||||
* @return {Buffer} The serialized object |
||||
*/ |
||||
return function serialize(arg) { |
||||
return new Buffer(new Cls(arg).encode().toBuffer()); |
||||
}; |
||||
}; |
||||
|
||||
var serializeCls = exports.serializeCls; |
||||
|
||||
/** |
||||
* Get the fully qualified (dotted) name of a ProtoBuf.Reflect value. |
||||
* @param {ProtoBuf.Reflect.Namespace} value The value to get the name of |
||||
* @return {string} The fully qualified name of the value |
||||
*/ |
||||
exports.fullyQualifiedName = function fullyQualifiedName(value) { |
||||
if (value === null || value === undefined) { |
||||
return ''; |
||||
} |
||||
var name = value.name; |
||||
var parent_name = fullyQualifiedName(value.parent); |
||||
if (parent_name !== '') { |
||||
name = parent_name + '.' + name; |
||||
} |
||||
return name; |
||||
}; |
||||
|
||||
var fullyQualifiedName = exports.fullyQualifiedName; |
||||
|
||||
/** |
||||
* Return a map from method names to method attributes for the service. |
||||
* @param {ProtoBuf.Reflect.Service} service The service to get attributes for |
||||
* @param {Object=} options Options to apply to these attributes |
||||
* @return {Object} The attributes map |
||||
*/ |
||||
exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service, |
||||
options) { |
||||
var prefix = '/' + fullyQualifiedName(service) + '/'; |
||||
var binaryAsBase64, longsAsStrings; |
||||
if (options) { |
||||
binaryAsBase64 = options.binaryAsBase64; |
||||
longsAsStrings = options.longsAsStrings; |
||||
} |
||||
/* This slightly awkward construction is used to make sure we only use |
||||
lodash@3.10.1-compatible functions. A previous version used |
||||
_.fromPairs, which would be cleaner, but was introduced in lodash |
||||
version 4 */ |
||||
return _.zipObject(_.map(service.children, function(method) { |
||||
return _.camelCase(method.name); |
||||
}), _.map(service.children, function(method) { |
||||
return { |
||||
originalName: method.name, |
||||
path: prefix + method.name, |
||||
requestStream: method.requestStream, |
||||
responseStream: method.responseStream, |
||||
requestType: method.resolvedRequestType, |
||||
responseType: method.resolvedResponseType, |
||||
requestSerialize: serializeCls(method.resolvedRequestType.build()), |
||||
requestDeserialize: deserializeCls(method.resolvedRequestType.build(), |
||||
binaryAsBase64, longsAsStrings), |
||||
responseSerialize: serializeCls(method.resolvedResponseType.build()), |
||||
responseDeserialize: deserializeCls(method.resolvedResponseType.build(), |
||||
binaryAsBase64, longsAsStrings) |
||||
}; |
||||
})); |
||||
}; |
||||
|
||||
var getProtobufServiceAttrs = exports.getProtobufServiceAttrs; |
||||
|
||||
/** |
||||
* Load a gRPC object from an existing ProtoBuf.Reflect object. |
||||
* @param {ProtoBuf.Reflect.Namespace} value The ProtoBuf object to load. |
||||
* @param {Object=} options Options to apply to the loaded object |
||||
* @return {Object<string, *>} The resulting gRPC object |
||||
*/ |
||||
exports.loadObject = function loadObject(value, options) { |
||||
var result = {}; |
||||
if (!value) { |
||||
return value; |
||||
} |
||||
if (value.hasOwnProperty('ns')) { |
||||
return loadObject(value.ns, options); |
||||
} |
||||
if (value.className === 'Namespace') { |
||||
_.each(value.children, function(child) { |
||||
result[child.name] = loadObject(child, options); |
||||
}); |
||||
return result; |
||||
} else if (value.className === 'Service') { |
||||
return client.makeClientConstructor(getProtobufServiceAttrs(value, options), |
||||
options); |
||||
} else if (value.className === 'Message' || value.className === 'Enum') { |
||||
return value.build(); |
||||
} else { |
||||
return value; |
||||
} |
||||
}; |
||||
|
||||
/** |
||||
* The primary purpose of this method is to distinguish between reflection |
||||
* objects from different versions of ProtoBuf.js. This is just a heuristic, |
||||
* checking for properties that are (currently) specific to this version of |
||||
* ProtoBuf.js |
||||
* @param {Object} obj The object to check |
||||
* @return {boolean} Whether the object appears to be a Protobuf.js 5 |
||||
* ReflectionObject |
||||
*/ |
||||
exports.isProbablyProtobufJs5 = function isProbablyProtobufJs5(obj) { |
||||
return _.isArray(obj.children) && (typeof obj.build === 'function'); |
||||
}; |
@ -0,0 +1,170 @@ |
||||
/* |
||||
* |
||||
* Copyright 2017, 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. |
||||
* |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
var _ = require('lodash'); |
||||
var client = require('./client'); |
||||
|
||||
/** |
||||
* Get a function that deserializes a specific type of protobuf. |
||||
* @param {function()} cls The constructor of the message type to deserialize |
||||
* @param {bool=} binaryAsBase64 Deserialize bytes fields as base64 strings |
||||
* instead of Buffers. Defaults to false |
||||
* @param {bool=} longsAsStrings Deserialize long values as strings instead of |
||||
* objects. Defaults to true |
||||
* @return {function(Buffer):cls} The deserialization function |
||||
*/ |
||||
exports.deserializeCls = function deserializeCls(cls, options) { |
||||
var conversion_options = { |
||||
defaults: true, |
||||
bytes: options.binaryAsBase64 ? String : Buffer, |
||||
longs: options.longsAsStrings ? String : null, |
||||
enums: options.enumsAsStrings ? String : null, |
||||
oneofs: true |
||||
}; |
||||
/** |
||||
* Deserialize a buffer to a message object |
||||
* @param {Buffer} arg_buf The buffer to deserialize |
||||
* @return {cls} The resulting object |
||||
*/ |
||||
return function deserialize(arg_buf) { |
||||
return cls.decode(arg_buf).toObject(conversion_options); |
||||
}; |
||||
}; |
||||
|
||||
var deserializeCls = exports.deserializeCls; |
||||
|
||||
/** |
||||
* Get a function that serializes objects to a buffer by protobuf class. |
||||
* @param {function()} Cls The constructor of the message type to serialize |
||||
* @return {function(Cls):Buffer} The serialization function |
||||
*/ |
||||
exports.serializeCls = function serializeCls(cls) { |
||||
/** |
||||
* Serialize an object to a Buffer |
||||
* @param {Object} arg The object to serialize |
||||
* @return {Buffer} The serialized object |
||||
*/ |
||||
return function serialize(arg) { |
||||
var message = cls.fromObject(arg); |
||||
return cls.encode(message).finish(); |
||||
}; |
||||
}; |
||||
|
||||
var serializeCls = exports.serializeCls; |
||||
|
||||
/** |
||||
* Get the fully qualified (dotted) name of a ProtoBuf.Reflect value. |
||||
* @param {ProtoBuf.ReflectionObject} value The value to get the name of |
||||
* @return {string} The fully qualified name of the value |
||||
*/ |
||||
exports.fullyQualifiedName = function fullyQualifiedName(value) { |
||||
if (value === null || value === undefined) { |
||||
return ''; |
||||
} |
||||
var name = value.name; |
||||
var parent_fqn = fullyQualifiedName(value.parent); |
||||
if (parent_fqn !== '') { |
||||
name = parent_fqn + '.' + name; |
||||
} |
||||
return name; |
||||
}; |
||||
|
||||
var fullyQualifiedName = exports.fullyQualifiedName; |
||||
|
||||
/** |
||||
* Return a map from method names to method attributes for the service. |
||||
* @param {ProtoBuf.Service} service The service to get attributes for |
||||
* @param {Object=} options Options to apply to these attributes |
||||
* @return {Object} The attributes map |
||||
*/ |
||||
exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service, |
||||
options) { |
||||
var prefix = '/' + fullyQualifiedName(service) + '/'; |
||||
service.resolveAll(); |
||||
return _.zipObject(_.map(service.methods, function(method) { |
||||
return _.camelCase(method.name); |
||||
}), _.map(service.methods, function(method) { |
||||
return { |
||||
originalName: method.name, |
||||
path: prefix + method.name, |
||||
requestStream: !!method.requestStream, |
||||
responseStream: !!method.responseStream, |
||||
requestType: method.resolvedRequestType, |
||||
responseType: method.resolvedResponseType, |
||||
requestSerialize: serializeCls(method.resolvedRequestType), |
||||
requestDeserialize: deserializeCls(method.resolvedRequestType, options), |
||||
responseSerialize: serializeCls(method.resolvedResponseType), |
||||
responseDeserialize: deserializeCls(method.resolvedResponseType, options) |
||||
}; |
||||
})); |
||||
}; |
||||
|
||||
var getProtobufServiceAttrs = exports.getProtobufServiceAttrs; |
||||
|
||||
exports.loadObject = function loadObject(value, options) { |
||||
var result = {}; |
||||
if (!value) { |
||||
return value; |
||||
} |
||||
if (value.hasOwnProperty('methods')) { |
||||
// It's a service object
|
||||
var service_attrs = getProtobufServiceAttrs(value, options); |
||||
return client.makeClientConstructor(service_attrs); |
||||
} |
||||
|
||||
if (value.hasOwnProperty('nested')) { |
||||
// It's a namespace or root object
|
||||
_.each(value.nested, function(nested, name) { |
||||
result[name] = loadObject(nested, options); |
||||
}); |
||||
return result; |
||||
} |
||||
|
||||
// Otherwise, it's not something we need to change
|
||||
return value; |
||||
}; |
||||
|
||||
/** |
||||
* The primary purpose of this method is to distinguish between reflection |
||||
* objects from different versions of ProtoBuf.js. This is just a heuristic, |
||||
* checking for properties that are (currently) specific to this version of |
||||
* ProtoBuf.js |
||||
* @param {Object} obj The object to check |
||||
* @return {boolean} Whether the object appears to be a Protobuf.js 6 |
||||
* ReflectionObject |
||||
*/ |
||||
exports.isProbablyProtobufJs6 = function isProbablyProtobufJs6(obj) { |
||||
return (typeof obj.root === 'object') && (typeof obj.resolve === 'function'); |
||||
}; |
@ -0,0 +1,4 @@ |
||||
include grpc_version.py |
||||
include reflection_commands.py |
||||
graft grpc_reflection |
||||
global-exclude *.pyc |
@ -0,0 +1,58 @@ |
||||
#!/usr/bin/env ruby |
||||
|
||||
# Copyright 2015, 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. |
||||
|
||||
# Attempt to reproduce |
||||
# https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues/1327 |
||||
|
||||
require_relative './end2end_common' |
||||
|
||||
def main |
||||
server_port = '' |
||||
OptionParser.new do |opts| |
||||
opts.on('--client_control_port=P', String) do |
||||
STDERR.puts 'client control port not used' |
||||
end |
||||
opts.on('--server_port=P', String) do |p| |
||||
server_port = p |
||||
end |
||||
end.parse! |
||||
|
||||
thd = Thread.new do |
||||
stub = Echo::EchoServer::Stub.new("localhost:#{server_port}", |
||||
:this_channel_is_insecure) |
||||
stub.echo(Echo::EchoRequest.new(request: 'hello')) |
||||
fail 'the clients rpc in this test shouldnt complete. ' \ |
||||
'expecting SIGINT to happen in the middle of the call' |
||||
end |
||||
thd.join |
||||
end |
||||
|
||||
main |
@ -0,0 +1,114 @@ |
||||
#!/usr/bin/env ruby |
||||
|
||||
# Copyright 2016, 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. |
||||
|
||||
require_relative './end2end_common' |
||||
|
||||
# Service that sleeps for a long time upon receiving an 'echo request' |
||||
# Also, this notifies @call_started_cv once it has received a request. |
||||
class SleepingEchoServerImpl < Echo::EchoServer::Service |
||||
def initialize(call_started, call_started_mu, call_started_cv) |
||||
@call_started = call_started |
||||
@call_started_mu = call_started_mu |
||||
@call_started_cv = call_started_cv |
||||
end |
||||
|
||||
def echo(echo_req, _) |
||||
@call_started_mu.synchronize do |
||||
@call_started.set_true |
||||
@call_started_cv.signal |
||||
end |
||||
sleep 1000 |
||||
Echo::EchoReply.new(response: echo_req.request) |
||||
end |
||||
end |
||||
|
||||
# Mutable boolean |
||||
class BoolHolder |
||||
attr_reader :val |
||||
|
||||
def init |
||||
@val = false |
||||
end |
||||
|
||||
def set_true |
||||
@val = true |
||||
end |
||||
end |
||||
|
||||
def main |
||||
STDERR.puts 'start server' |
||||
|
||||
call_started = BoolHolder.new |
||||
call_started_mu = Mutex.new |
||||
call_started_cv = ConditionVariable.new |
||||
|
||||
service_impl = SleepingEchoServerImpl.new(call_started, |
||||
call_started_mu, |
||||
call_started_cv) |
||||
server_runner = ServerRunner.new(service_impl) |
||||
server_port = server_runner.run |
||||
|
||||
STDERR.puts 'start client' |
||||
_, client_pid = start_client('killed_client_thread_client.rb', |
||||
server_port) |
||||
|
||||
call_started_mu.synchronize do |
||||
call_started_cv.wait(call_started_mu) until call_started.val |
||||
end |
||||
|
||||
# SIGINT the child process now that it's |
||||
# in the middle of an RPC (happening on a non-main thread) |
||||
Process.kill('SIGINT', client_pid) |
||||
STDERR.puts 'sent shutdown' |
||||
|
||||
begin |
||||
Timeout.timeout(10) do |
||||
Process.wait(client_pid) |
||||
end |
||||
rescue Timeout::Error |
||||
STDERR.puts "timeout wait for client pid #{client_pid}" |
||||
Process.kill('SIGKILL', client_pid) |
||||
Process.wait(client_pid) |
||||
STDERR.puts 'killed client child' |
||||
raise 'Timed out waiting for client process. ' \ |
||||
'It likely hangs when killed while in the middle of an rpc' |
||||
end |
||||
|
||||
client_exit_code = $CHILD_STATUS |
||||
if client_exit_code.termsig != 2 # SIGINT |
||||
fail 'expected client exit from SIGINT ' \ |
||||
"but got child status: #{client_exit_code}" |
||||
end |
||||
|
||||
server_runner.stop |
||||
end |
||||
|
||||
main |
Binary file not shown.
@ -0,0 +1,237 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017, 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. |
||||
* |
||||
*/ |
||||
|
||||
#include "test/core/end2end/end2end_tests.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/sync.h> |
||||
#include <grpc/support/thd.h> |
||||
#include <grpc/support/time.h> |
||||
#include <grpc/support/useful.h> |
||||
|
||||
#include "test/core/end2end/cq_verifier.h" |
||||
|
||||
#define MAX_PING_STRIKES 1 |
||||
|
||||
static void *tag(intptr_t t) { return (void *)t; } |
||||
|
||||
static void drain_cq(grpc_completion_queue *cq) { |
||||
grpc_event ev; |
||||
do { |
||||
ev = grpc_completion_queue_next(cq, grpc_timeout_seconds_to_deadline(5), |
||||
NULL); |
||||
} while (ev.type != GRPC_QUEUE_SHUTDOWN); |
||||
} |
||||
|
||||
static void shutdown_server(grpc_end2end_test_fixture *f) { |
||||
if (!f->server) return; |
||||
grpc_server_destroy(f->server); |
||||
f->server = NULL; |
||||
} |
||||
|
||||
static void shutdown_client(grpc_end2end_test_fixture *f) { |
||||
if (!f->client) return; |
||||
grpc_channel_destroy(f->client); |
||||
f->client = NULL; |
||||
} |
||||
|
||||
static void end_test(grpc_end2end_test_fixture *f) { |
||||
shutdown_server(f); |
||||
shutdown_client(f); |
||||
|
||||
grpc_completion_queue_shutdown(f->cq); |
||||
drain_cq(f->cq); |
||||
grpc_completion_queue_destroy(f->cq); |
||||
} |
||||
|
||||
static void test_bad_ping(grpc_end2end_test_config config) { |
||||
grpc_end2end_test_fixture f = config.create_fixture(NULL, NULL); |
||||
cq_verifier *cqv = cq_verifier_create(f.cq); |
||||
grpc_arg client_a[] = {{.type = GRPC_ARG_INTEGER, |
||||
.key = GRPC_ARG_HTTP2_MIN_TIME_BETWEEN_PINGS_MS, |
||||
.value.integer = 0}, |
||||
{.type = GRPC_ARG_INTEGER, |
||||
.key = GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, |
||||
.value.integer = 20}, |
||||
{.type = GRPC_ARG_INTEGER, |
||||
.key = GRPC_ARG_HTTP2_BDP_PROBE, |
||||
.value.integer = 0}}; |
||||
grpc_arg server_a[] = { |
||||
{.type = GRPC_ARG_INTEGER, |
||||
.key = GRPC_ARG_HTTP2_MIN_PING_INTERVAL_WITHOUT_DATA_MS, |
||||
.value.integer = 300000 /* 5 minutes */}, |
||||
{.type = GRPC_ARG_INTEGER, |
||||
.key = GRPC_ARG_HTTP2_MAX_PING_STRIKES, |
||||
.value.integer = MAX_PING_STRIKES}}; |
||||
grpc_channel_args client_args = {.num_args = GPR_ARRAY_SIZE(client_a), |
||||
.args = client_a}; |
||||
grpc_channel_args server_args = {.num_args = GPR_ARRAY_SIZE(server_a), |
||||
.args = server_a}; |
||||
|
||||
config.init_client(&f, &client_args); |
||||
config.init_server(&f, &server_args); |
||||
|
||||
grpc_call *c; |
||||
grpc_call *s; |
||||
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(10); |
||||
grpc_op ops[6]; |
||||
grpc_op *op; |
||||
grpc_metadata_array initial_metadata_recv; |
||||
grpc_metadata_array trailing_metadata_recv; |
||||
grpc_metadata_array request_metadata_recv; |
||||
grpc_call_details call_details; |
||||
grpc_status_code status; |
||||
grpc_call_error error; |
||||
grpc_slice details; |
||||
int was_cancelled = 2; |
||||
|
||||
c = grpc_channel_create_call( |
||||
f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, |
||||
grpc_slice_from_static_string("/foo"), |
||||
get_host_override_slice("foo.test.google.fr:1234", config), deadline, |
||||
NULL); |
||||
GPR_ASSERT(c); |
||||
|
||||
grpc_metadata_array_init(&initial_metadata_recv); |
||||
grpc_metadata_array_init(&trailing_metadata_recv); |
||||
grpc_metadata_array_init(&request_metadata_recv); |
||||
grpc_call_details_init(&call_details); |
||||
|
||||
memset(ops, 0, sizeof(ops)); |
||||
op = ops; |
||||
op->op = GRPC_OP_SEND_INITIAL_METADATA; |
||||
op->data.send_initial_metadata.count = 0; |
||||
op->data.send_initial_metadata.metadata = NULL; |
||||
op->flags = 0; |
||||
op->reserved = NULL; |
||||
op++; |
||||
op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
||||
op->flags = 0; |
||||
op->reserved = NULL; |
||||
op++; |
||||
op->op = GRPC_OP_RECV_INITIAL_METADATA; |
||||
op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; |
||||
op->flags = 0; |
||||
op->reserved = NULL; |
||||
op++; |
||||
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
||||
op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; |
||||
op->data.recv_status_on_client.status = &status; |
||||
op->data.recv_status_on_client.status_details = &details; |
||||
op->flags = 0; |
||||
op->reserved = NULL; |
||||
op++; |
||||
error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); |
||||
GPR_ASSERT(GRPC_CALL_OK == error); |
||||
|
||||
error = |
||||
grpc_server_request_call(f.server, &s, &call_details, |
||||
&request_metadata_recv, f.cq, f.cq, tag(101)); |
||||
GPR_ASSERT(GRPC_CALL_OK == error); |
||||
CQ_EXPECT_COMPLETION(cqv, tag(101), 1); |
||||
cq_verify(cqv); |
||||
|
||||
// Send too many pings to the server to trigger the punishment:
|
||||
// The first ping is sent after data frames, it won't trigger a ping strike.
|
||||
// Each of the following pings will trigger a ping strike, and we need at
|
||||
// least (MAX_PING_STRIKES + 1) strikes to trigger the punishment. So
|
||||
// (MAX_PING_STRIKES + 2) pings are needed here.
|
||||
int i; |
||||
for (i = 200; i < 202 + MAX_PING_STRIKES; i++) { |
||||
grpc_channel_ping(f.client, f.cq, tag(i), NULL); |
||||
CQ_EXPECT_COMPLETION(cqv, tag(i), 1); |
||||
cq_verify(cqv); |
||||
} |
||||
|
||||
memset(ops, 0, sizeof(ops)); |
||||
op = ops; |
||||
op->op = GRPC_OP_SEND_INITIAL_METADATA; |
||||
op->data.send_initial_metadata.count = 0; |
||||
op->flags = 0; |
||||
op->reserved = NULL; |
||||
op++; |
||||
op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; |
||||
op->data.send_status_from_server.trailing_metadata_count = 0; |
||||
op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; |
||||
grpc_slice status_details = grpc_slice_from_static_string("xyz"); |
||||
op->data.send_status_from_server.status_details = &status_details; |
||||
op->flags = 0; |
||||
op->reserved = NULL; |
||||
op++; |
||||
op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; |
||||
op->data.recv_close_on_server.cancelled = &was_cancelled; |
||||
op->flags = 0; |
||||
op->reserved = NULL; |
||||
op++; |
||||
error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); |
||||
GPR_ASSERT(GRPC_CALL_OK == error); |
||||
|
||||
CQ_EXPECT_COMPLETION(cqv, tag(102), 1); |
||||
CQ_EXPECT_COMPLETION(cqv, tag(1), 1); |
||||
cq_verify(cqv); |
||||
|
||||
grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead)); |
||||
CQ_EXPECT_COMPLETION(cqv, tag(0xdead), 1); |
||||
cq_verify(cqv); |
||||
|
||||
grpc_call_destroy(s); |
||||
|
||||
// The connection should be closed immediately after the misbehaved pings,
|
||||
// the in-progress RPC should fail.
|
||||
GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE); |
||||
GPR_ASSERT(0 == grpc_slice_str_cmp(details, "Endpoint read failed")); |
||||
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); |
||||
validate_host_override_string("foo.test.google.fr:1234", call_details.host, |
||||
config); |
||||
GPR_ASSERT(was_cancelled == 1); |
||||
|
||||
grpc_slice_unref(details); |
||||
grpc_metadata_array_destroy(&initial_metadata_recv); |
||||
grpc_metadata_array_destroy(&trailing_metadata_recv); |
||||
grpc_metadata_array_destroy(&request_metadata_recv); |
||||
grpc_call_details_destroy(&call_details); |
||||
grpc_call_destroy(c); |
||||
cq_verifier_destroy(cqv); |
||||
end_test(&f); |
||||
config.tear_down_data(&f); |
||||
} |
||||
|
||||
void bad_ping(grpc_end2end_test_config config) { |
||||
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION); |
||||
test_bad_ping(config); |
||||
} |
||||
|
||||
void bad_ping_pre_init(void) {} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue