From 2eedca72d53e9987da3a3a29961736312baf8b6f Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Thu, 5 May 2016 18:20:09 -0700 Subject: [PATCH 01/20] Check the value of Next() in async examples --- examples/cpp/helloworld/greeter_async_client.cc | 4 +++- examples/cpp/helloworld/greeter_async_server.cc | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/cpp/helloworld/greeter_async_client.cc b/examples/cpp/helloworld/greeter_async_client.cc index c1f5eb55f05..33de59fb957 100644 --- a/examples/cpp/helloworld/greeter_async_client.cc +++ b/examples/cpp/helloworld/greeter_async_client.cc @@ -87,7 +87,9 @@ class GreeterClient { void* got_tag; bool ok = false; // Block until the next result is available in the completion queue "cq". - cq.Next(&got_tag, &ok); + // The return value of Next should always be checked. This return value + // tells us whether there is any kind of event or the cq_ is shutting down. + GPR_ASSERT(cq.Next(&got_tag, &ok)); // Verify that the result from "cq" corresponds, by its tag, our previous // request. diff --git a/examples/cpp/helloworld/greeter_async_server.cc b/examples/cpp/helloworld/greeter_async_server.cc index 64e065b1e40..ead44182e57 100644 --- a/examples/cpp/helloworld/greeter_async_server.cc +++ b/examples/cpp/helloworld/greeter_async_server.cc @@ -160,7 +160,9 @@ class ServerImpl final { // Block waiting to read the next event from the completion queue. The // event is uniquely identified by its tag, which in this case is the // memory address of a CallData instance. - cq_->Next(&tag, &ok); + // The return value of Next should always be checked. This return value + // tells us whether there is any kind of event or cq_ is shutting down. + GPR_ASSERT(cq_->Next(&tag, &ok)); GPR_ASSERT(ok); static_cast(tag)->Proceed(); } From d55ddbcbe34f69d7971908c148b8a24fb95f04f8 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 19 May 2016 16:24:59 -0700 Subject: [PATCH 02/20] php: ran php-cs-fixer again --- src/php/tests/interop/interop_client.php | 3 +- src/php/tests/interop/metrics_client.php | 6 +- src/php/tests/interop/stress_client.php | 103 ++++++++++++----------- 3 files changed, 58 insertions(+), 54 deletions(-) diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php index 565bfce74f7..c5bb7c490e2 100755 --- a/src/php/tests/interop/interop_client.php +++ b/src/php/tests/interop/interop_client.php @@ -477,7 +477,8 @@ function _makeStub($args) return $stub; } -function interop_main($args, $stub = false) { +function interop_main($args, $stub = false) +{ if (!$stub) { $stub = _makeStub($args); } diff --git a/src/php/tests/interop/metrics_client.php b/src/php/tests/interop/metrics_client.php index 46f4212f773..19510dc5d82 100644 --- a/src/php/tests/interop/metrics_client.php +++ b/src/php/tests/interop/metrics_client.php @@ -39,11 +39,11 @@ $server_port = (count($parts) == 2) ? $parts[1] : ''; $socket = socket_create(AF_INET, SOCK_STREAM, 0); if (@!socket_connect($socket, $server_host, $server_port)) { - echo "Cannot connect to merics server...\n"; - exit(1); + echo "Cannot connect to merics server...\n"; + exit(1); } socket_write($socket, 'qps'); while ($out = socket_read($socket, 1024)) { - echo "$out\n"; + echo "$out\n"; } socket_close($socket); diff --git a/src/php/tests/interop/stress_client.php b/src/php/tests/interop/stress_client.php index 2339f0d105d..419ef5be438 100644 --- a/src/php/tests/interop/stress_client.php +++ b/src/php/tests/interop/stress_client.php @@ -32,50 +32,52 @@ * */ -include_once('interop_client.php'); +include_once 'interop_client.php'; -function stress_main($args) { - mt_srand(); - set_time_limit(0); +function stress_main($args) +{ + mt_srand(); + set_time_limit(0); - // open socket to listen as metrics server - $socket = socket_create(AF_INET, SOCK_STREAM, 0); - socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1); - if (@!socket_bind($socket, 'localhost', $args['metrics_port'])) { - echo "Cannot create socket for metrics server...\n"; - exit(1); - } - socket_listen($socket); - socket_set_nonblock($socket); + // open socket to listen as metrics server + $socket = socket_create(AF_INET, SOCK_STREAM, 0); + socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1); + if (@!socket_bind($socket, 'localhost', $args['metrics_port'])) { + echo "Cannot create socket for metrics server...\n"; + exit(1); + } + socket_listen($socket); + socket_set_nonblock($socket); - $start_time = microtime(true); - $count = 0; - $deadline = $args['test_duration_secs'] ? - ($start_time + $args['test_duration_secs']) : false; - $num_test_cases = count($args['test_cases']); - $stub = false; + $start_time = microtime(true); + $count = 0; + $deadline = $args['test_duration_secs'] ? + ($start_time + $args['test_duration_secs']) : false; + $num_test_cases = count($args['test_cases']); + $stub = false; - while (true) { - $current_time = microtime(true); - if ($deadline && $current_time > $deadline) { - break; - } - if ($client_connection = socket_accept($socket)) { - // there is an incoming request, respond with qps metrics - $input = socket_read($client_connection, 1024); - $qps = round($count / ($current_time - $start_time)); - socket_write($client_connection, "qps: $qps"); - socket_close($client_connection); - } else { - // do actual work, run one interop test case - $args['test_case'] = - $args['test_cases'][mt_rand(0, $num_test_cases - 1)]; - $stub = @interop_main($args, $stub); - $count++; + while (true) { + $current_time = microtime(true); + if ($deadline && $current_time > $deadline) { + break; + } + if ($client_connection = socket_accept($socket)) { + // there is an incoming request, respond with qps metrics + $input = socket_read($client_connection, 1024); + $qps = round($count / ($current_time - $start_time)); + socket_write($client_connection, "qps: $qps"); + socket_close($client_connection); + } else { + // do actual work, run one interop test case + $args['test_case'] = + $args['test_cases'][mt_rand(0, $num_test_cases - 1)]; + $stub = @interop_main($args, $stub); + ++$count; + } } - } - socket_close($socket); - echo "Number of interop tests run in $args[test_duration_secs] seconds: $count.\n"; + socket_close($socket); + echo "Number of interop tests run in $args[test_duration_secs] ". + "seconds: $count.\n"; } // process command line arguments @@ -85,31 +87,32 @@ $raw_args = getopt('', 'metrics_port::', 'test_duration_secs::', 'num_channels_per_server::', - 'num_stubs_per_channel::']); + 'num_stubs_per_channel::', + ]); $args = []; if (empty($raw_args['server_addresses'])) { - $args['server_host'] = 'localhost'; - $args['server_port'] = '8080'; + $args['server_host'] = 'localhost'; + $args['server_port'] = '8080'; } else { - $parts = explode(':', $raw_args['server_addresses']); - $args['server_host'] = $parts[0]; - $args['server_port'] = (count($parts) == 2) ? $parts[1] : ''; + $parts = explode(':', $raw_args['server_addresses']); + $args['server_host'] = $parts[0]; + $args['server_port'] = (count($parts) == 2) ? $parts[1] : ''; } $args['metrics_port'] = empty($raw_args['metrics_port']) ? - '8081' : $args['metrics_port']; + '8081' : $args['metrics_port']; $args['test_duration_secs'] = empty($raw_args['test_duration_secs']) || - $raw_args['test_duration_secs'] == -1 ? - false : $raw_args['test_duration_secs']; + $raw_args['test_duration_secs'] == -1 ? + false : $raw_args['test_duration_secs']; $test_cases = []; $test_case_strs = explode(',', $raw_args['test_cases']); foreach ($test_case_strs as $test_case_str) { - $parts = explode(':', $test_case_str); - $test_cases = array_merge($test_cases, array_fill(0, $parts[1], $parts[0])); + $parts = explode(':', $test_case_str); + $test_cases = array_merge($test_cases, array_fill(0, $parts[1], $parts[0])); } $args['test_cases'] = $test_cases; From 46d94bb4aac9f075008229afe815d58072b8baea Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 19 May 2016 16:47:52 -0700 Subject: [PATCH 03/20] php: fix examples/ directory as well --- examples/php/greeter_client.php | 26 +- examples/php/helloworld.php | 160 ++-- examples/php/route_guide/route_guide.php | 768 ++++++++++-------- .../php/route_guide/route_guide_client.php | 264 +++--- 4 files changed, 648 insertions(+), 570 deletions(-) diff --git a/examples/php/greeter_client.php b/examples/php/greeter_client.php index 718ef88c644..a5c0865393d 100644 --- a/examples/php/greeter_client.php +++ b/examples/php/greeter_client.php @@ -32,19 +32,21 @@ * */ -require dirname(__FILE__) . '/vendor/autoload.php'; -require dirname(__FILE__) . '/helloworld.php'; +require dirname(__FILE__).'/vendor/autoload.php'; +require dirname(__FILE__).'/helloworld.php'; -function greet($name) { - $client = new helloworld\GreeterClient('localhost:50051', [ - 'credentials' => Grpc\ChannelCredentials::createInsecure() - ]); - $request = new helloworld\HelloRequest(); - $request->setName($name); - list($reply, $status) = $client->SayHello($request)->wait(); - $message = $reply->getMessage(); - return $message; +function greet($name) +{ + $client = new helloworld\GreeterClient('localhost:50051', [ + 'credentials' => Grpc\ChannelCredentials::createInsecure(), + ]); + $request = new helloworld\HelloRequest(); + $request->setName($name); + list($reply, $status) = $client->SayHello($request)->wait(); + $message = $reply->getMessage(); + + return $message; } $name = !empty($argv[1]) ? $argv[1] : 'world'; -print(greet($name)."\n"); +echo greet($name)."\n"; diff --git a/examples/php/helloworld.php b/examples/php/helloworld.php index 50923e6fcdc..697f52aa653 100644 --- a/examples/php/helloworld.php +++ b/examples/php/helloworld.php @@ -5,154 +5,164 @@ namespace helloworld { - class HelloRequest extends \DrSlump\Protobuf\Message { - - /** @var string */ + class HelloRequest extends \DrSlump\Protobuf\Message + { + /** @var string */ public $name = null; - /** @var \Closure[] */ protected static $__extensions = array(); - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'helloworld.HelloRequest'); + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'helloworld.HelloRequest'); // OPTIONAL STRING name = 1 $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = "name"; - $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } + $f->number = 1; + $f->name = 'name'; + $f->type = \DrSlump\Protobuf::TYPE_STRING; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); - return $descriptor; - } + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; + } /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasName(){ - return $this->_has(1); + public function hasName() + { + return $this->_has(1); } - + /** - * Clear value + * Clear value. * * @return \helloworld\HelloRequest */ - public function clearName(){ - return $this->_clear(1); + public function clearName() + { + return $this->_clear(1); } - + /** - * Get value + * Get value. * * @return string */ - public function getName(){ - return $this->_get(1); + public function getName() + { + return $this->_get(1); } - + /** - * Set value + * Set value. * * @param string $value + * * @return \helloworld\HelloRequest */ - public function setName( $value){ - return $this->_set(1, $value); + public function setName($value) + { + return $this->_set(1, $value); } } } namespace helloworld { - class HelloReply extends \DrSlump\Protobuf\Message { - - /** @var string */ + class HelloReply extends \DrSlump\Protobuf\Message + { + /** @var string */ public $message = null; - /** @var \Closure[] */ protected static $__extensions = array(); - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'helloworld.HelloReply'); + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'helloworld.HelloReply'); // OPTIONAL STRING message = 1 $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = "message"; - $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } + $f->number = 1; + $f->name = 'message'; + $f->type = \DrSlump\Protobuf::TYPE_STRING; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); - return $descriptor; - } + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; + } /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasMessage(){ - return $this->_has(1); + public function hasMessage() + { + return $this->_has(1); } - + /** - * Clear value + * Clear value. * * @return \helloworld\HelloReply */ - public function clearMessage(){ - return $this->_clear(1); + public function clearMessage() + { + return $this->_clear(1); } - + /** - * Get value + * Get value. * * @return string */ - public function getMessage(){ - return $this->_get(1); + public function getMessage() + { + return $this->_get(1); } - + /** - * Set value + * Set value. * * @param string $value + * * @return \helloworld\HelloReply */ - public function setMessage( $value){ - return $this->_set(1, $value); + public function setMessage($value) + { + return $this->_set(1, $value); } } } namespace helloworld { - class GreeterClient extends \Grpc\BaseStub { - - public function __construct($hostname, $opts) { - parent::__construct($hostname, $opts); - } + class GreeterClient extends \Grpc\BaseStub + { + public function __construct($hostname, $opts) + { + parent::__construct($hostname, $opts); + } /** * @param helloworld\HelloRequest $input */ - public function SayHello(\helloworld\HelloRequest $argument, $metadata = array(), $options = array()) { - return $this->_simpleRequest('/helloworld.Greeter/SayHello', $argument, '\helloworld\HelloReply::deserialize', $metadata, $options); + public function SayHello(\helloworld\HelloRequest $argument, $metadata = array(), $options = array()) + { + return $this->_simpleRequest('/helloworld.Greeter/SayHello', $argument, '\helloworld\HelloReply::deserialize', $metadata, $options); } } } diff --git a/examples/php/route_guide/route_guide.php b/examples/php/route_guide/route_guide.php index 0de319890d5..65045d01e17 100644 --- a/examples/php/route_guide/route_guide.php +++ b/examples/php/route_guide/route_guide.php @@ -5,725 +5,785 @@ namespace routeguide { - class Point extends \DrSlump\Protobuf\Message { - - /** @var int */ + class Point extends \DrSlump\Protobuf\Message + { + /** @var int */ public $latitude = 0; - + /** @var int */ public $longitude = 0; - /** @var \Closure[] */ protected static $__extensions = array(); - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Point'); + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Point'); // OPTIONAL INT32 latitude = 1 $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = "latitude"; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); + $f->number = 1; + $f->name = 'latitude'; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); // OPTIONAL INT32 longitude = 2 $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = "longitude"; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); + $f->number = 2; + $f->name = 'longitude'; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); + + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; } - return $descriptor; - } - /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasLatitude(){ - return $this->_has(1); + public function hasLatitude() + { + return $this->_has(1); } - + /** - * Clear value + * Clear value. * * @return \routeguide\Point */ - public function clearLatitude(){ - return $this->_clear(1); + public function clearLatitude() + { + return $this->_clear(1); } - + /** - * Get value + * Get value. * * @return int */ - public function getLatitude(){ - return $this->_get(1); + public function getLatitude() + { + return $this->_get(1); } - + /** - * Set value + * Set value. * * @param int $value + * * @return \routeguide\Point */ - public function setLatitude( $value){ - return $this->_set(1, $value); + public function setLatitude($value) + { + return $this->_set(1, $value); } - + /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasLongitude(){ - return $this->_has(2); + public function hasLongitude() + { + return $this->_has(2); } - + /** - * Clear value + * Clear value. * * @return \routeguide\Point */ - public function clearLongitude(){ - return $this->_clear(2); + public function clearLongitude() + { + return $this->_clear(2); } - + /** - * Get value + * Get value. * * @return int */ - public function getLongitude(){ - return $this->_get(2); + public function getLongitude() + { + return $this->_get(2); } - + /** - * Set value + * Set value. * * @param int $value + * * @return \routeguide\Point */ - public function setLongitude( $value){ - return $this->_set(2, $value); + public function setLongitude($value) + { + return $this->_set(2, $value); } } } namespace routeguide { - class Rectangle extends \DrSlump\Protobuf\Message { - - /** @var \routeguide\Point */ + class Rectangle extends \DrSlump\Protobuf\Message + { + /** @var \routeguide\Point */ public $lo = null; - + /** @var \routeguide\Point */ public $hi = null; - /** @var \Closure[] */ protected static $__extensions = array(); - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Rectangle'); + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Rectangle'); // OPTIONAL MESSAGE lo = 1 $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = "lo"; - $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\routeguide\Point'; - $descriptor->addField($f); + $f->number = 1; + $f->name = 'lo'; + $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\routeguide\Point'; + $descriptor->addField($f); // OPTIONAL MESSAGE hi = 2 $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = "hi"; - $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\routeguide\Point'; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); + $f->number = 2; + $f->name = 'hi'; + $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\routeguide\Point'; + $descriptor->addField($f); + + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; } - return $descriptor; - } - /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasLo(){ - return $this->_has(1); + public function hasLo() + { + return $this->_has(1); } - + /** - * Clear value + * Clear value. * * @return \routeguide\Rectangle */ - public function clearLo(){ - return $this->_clear(1); + public function clearLo() + { + return $this->_clear(1); } - + /** - * Get value + * Get value. * * @return \routeguide\Point */ - public function getLo(){ - return $this->_get(1); + public function getLo() + { + return $this->_get(1); } - + /** - * Set value + * Set value. * * @param \routeguide\Point $value + * * @return \routeguide\Rectangle */ - public function setLo(\routeguide\Point $value){ - return $this->_set(1, $value); + public function setLo(\routeguide\Point $value) + { + return $this->_set(1, $value); } - + /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasHi(){ - return $this->_has(2); + public function hasHi() + { + return $this->_has(2); } - + /** - * Clear value + * Clear value. * * @return \routeguide\Rectangle */ - public function clearHi(){ - return $this->_clear(2); + public function clearHi() + { + return $this->_clear(2); } - + /** - * Get value + * Get value. * * @return \routeguide\Point */ - public function getHi(){ - return $this->_get(2); + public function getHi() + { + return $this->_get(2); } - + /** - * Set value + * Set value. * * @param \routeguide\Point $value + * * @return \routeguide\Rectangle */ - public function setHi(\routeguide\Point $value){ - return $this->_set(2, $value); + public function setHi(\routeguide\Point $value) + { + return $this->_set(2, $value); } } } namespace routeguide { - class Feature extends \DrSlump\Protobuf\Message { - - /** @var string */ + class Feature extends \DrSlump\Protobuf\Message + { + /** @var string */ public $name = null; - + /** @var \routeguide\Point */ public $location = null; - /** @var \Closure[] */ protected static $__extensions = array(); - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Feature'); + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Feature'); // OPTIONAL STRING name = 1 $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = "name"; - $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $descriptor->addField($f); + $f->number = 1; + $f->name = 'name'; + $f->type = \DrSlump\Protobuf::TYPE_STRING; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); // OPTIONAL MESSAGE location = 2 $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = "location"; - $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\routeguide\Point'; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); + $f->number = 2; + $f->name = 'location'; + $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\routeguide\Point'; + $descriptor->addField($f); + + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; } - return $descriptor; - } - /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasName(){ - return $this->_has(1); + public function hasName() + { + return $this->_has(1); } - + /** - * Clear value + * Clear value. * * @return \routeguide\Feature */ - public function clearName(){ - return $this->_clear(1); + public function clearName() + { + return $this->_clear(1); } - + /** - * Get value + * Get value. * * @return string */ - public function getName(){ - return $this->_get(1); + public function getName() + { + return $this->_get(1); } - + /** - * Set value + * Set value. * * @param string $value + * * @return \routeguide\Feature */ - public function setName( $value){ - return $this->_set(1, $value); + public function setName($value) + { + return $this->_set(1, $value); } - + /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasLocation(){ - return $this->_has(2); + public function hasLocation() + { + return $this->_has(2); } - + /** - * Clear value + * Clear value. * * @return \routeguide\Feature */ - public function clearLocation(){ - return $this->_clear(2); + public function clearLocation() + { + return $this->_clear(2); } - + /** - * Get value + * Get value. * * @return \routeguide\Point */ - public function getLocation(){ - return $this->_get(2); + public function getLocation() + { + return $this->_get(2); } - + /** - * Set value + * Set value. * * @param \routeguide\Point $value + * * @return \routeguide\Feature */ - public function setLocation(\routeguide\Point $value){ - return $this->_set(2, $value); + public function setLocation(\routeguide\Point $value) + { + return $this->_set(2, $value); } } } namespace routeguide { - class RouteNote extends \DrSlump\Protobuf\Message { - - /** @var \routeguide\Point */ + class RouteNote extends \DrSlump\Protobuf\Message + { + /** @var \routeguide\Point */ public $location = null; - + /** @var string */ public $message = null; - /** @var \Closure[] */ protected static $__extensions = array(); - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteNote'); + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteNote'); // OPTIONAL MESSAGE location = 1 $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = "location"; - $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\routeguide\Point'; - $descriptor->addField($f); + $f->number = 1; + $f->name = 'location'; + $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\routeguide\Point'; + $descriptor->addField($f); // OPTIONAL STRING message = 2 $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = "message"; - $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); - } + $f->number = 2; + $f->name = 'message'; + $f->type = \DrSlump\Protobuf::TYPE_STRING; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); - return $descriptor; - } + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; + } /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasLocation(){ - return $this->_has(1); + public function hasLocation() + { + return $this->_has(1); } - + /** - * Clear value + * Clear value. * * @return \routeguide\RouteNote */ - public function clearLocation(){ - return $this->_clear(1); + public function clearLocation() + { + return $this->_clear(1); } - + /** - * Get value + * Get value. * * @return \routeguide\Point */ - public function getLocation(){ - return $this->_get(1); + public function getLocation() + { + return $this->_get(1); } - + /** - * Set value + * Set value. * * @param \routeguide\Point $value + * * @return \routeguide\RouteNote */ - public function setLocation(\routeguide\Point $value){ - return $this->_set(1, $value); + public function setLocation(\routeguide\Point $value) + { + return $this->_set(1, $value); } - + /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasMessage(){ - return $this->_has(2); + public function hasMessage() + { + return $this->_has(2); } - + /** - * Clear value + * Clear value. * * @return \routeguide\RouteNote */ - public function clearMessage(){ - return $this->_clear(2); + public function clearMessage() + { + return $this->_clear(2); } - + /** - * Get value + * Get value. * * @return string */ - public function getMessage(){ - return $this->_get(2); + public function getMessage() + { + return $this->_get(2); } - + /** - * Set value + * Set value. * * @param string $value + * * @return \routeguide\RouteNote */ - public function setMessage( $value){ - return $this->_set(2, $value); + public function setMessage($value) + { + return $this->_set(2, $value); } } } namespace routeguide { - class RouteSummary extends \DrSlump\Protobuf\Message { - - /** @var int */ + class RouteSummary extends \DrSlump\Protobuf\Message + { + /** @var int */ public $point_count = 0; - + /** @var int */ public $feature_count = 0; - + /** @var int */ public $distance = 0; - + /** @var int */ public $elapsed_time = 0; - /** @var \Closure[] */ protected static $__extensions = array(); - public static function descriptor() - { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteSummary'); + public static function descriptor() + { + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteSummary'); // OPTIONAL INT32 point_count = 1 $f = new \DrSlump\Protobuf\Field(); - $f->number = 1; - $f->name = "point_count"; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); + $f->number = 1; + $f->name = 'point_count'; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); // OPTIONAL INT32 feature_count = 2 $f = new \DrSlump\Protobuf\Field(); - $f->number = 2; - $f->name = "feature_count"; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); + $f->number = 2; + $f->name = 'feature_count'; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); // OPTIONAL INT32 distance = 3 $f = new \DrSlump\Protobuf\Field(); - $f->number = 3; - $f->name = "distance"; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); + $f->number = 3; + $f->name = 'distance'; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); // OPTIONAL INT32 elapsed_time = 4 $f = new \DrSlump\Protobuf\Field(); - $f->number = 4; - $f->name = "elapsed_time"; - $f->type = \DrSlump\Protobuf::TYPE_INT32; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->default = 0; - $descriptor->addField($f); - - foreach (self::$__extensions as $cb) { - $descriptor->addField($cb(), true); + $f->number = 4; + $f->name = 'elapsed_time'; + $f->type = \DrSlump\Protobuf::TYPE_INT32; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->default = 0; + $descriptor->addField($f); + + foreach (self::$__extensions as $cb) { + $descriptor->addField($cb(), true); + } + + return $descriptor; } - return $descriptor; - } - /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasPointCount(){ - return $this->_has(1); + public function hasPointCount() + { + return $this->_has(1); } - + /** - * Clear value + * Clear value. * * @return \routeguide\RouteSummary */ - public function clearPointCount(){ - return $this->_clear(1); + public function clearPointCount() + { + return $this->_clear(1); } - + /** - * Get value + * Get value. * * @return int */ - public function getPointCount(){ - return $this->_get(1); + public function getPointCount() + { + return $this->_get(1); } - + /** - * Set value + * Set value. * * @param int $value + * * @return \routeguide\RouteSummary */ - public function setPointCount( $value){ - return $this->_set(1, $value); + public function setPointCount($value) + { + return $this->_set(1, $value); } - + /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasFeatureCount(){ - return $this->_has(2); + public function hasFeatureCount() + { + return $this->_has(2); } - + /** - * Clear value + * Clear value. * * @return \routeguide\RouteSummary */ - public function clearFeatureCount(){ - return $this->_clear(2); + public function clearFeatureCount() + { + return $this->_clear(2); } - + /** - * Get value + * Get value. * * @return int */ - public function getFeatureCount(){ - return $this->_get(2); + public function getFeatureCount() + { + return $this->_get(2); } - + /** - * Set value + * Set value. * * @param int $value + * * @return \routeguide\RouteSummary */ - public function setFeatureCount( $value){ - return $this->_set(2, $value); + public function setFeatureCount($value) + { + return $this->_set(2, $value); } - + /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasDistance(){ - return $this->_has(3); + public function hasDistance() + { + return $this->_has(3); } - + /** - * Clear value + * Clear value. * * @return \routeguide\RouteSummary */ - public function clearDistance(){ - return $this->_clear(3); + public function clearDistance() + { + return $this->_clear(3); } - + /** - * Get value + * Get value. * * @return int */ - public function getDistance(){ - return $this->_get(3); + public function getDistance() + { + return $this->_get(3); } - + /** - * Set value + * Set value. * * @param int $value + * * @return \routeguide\RouteSummary */ - public function setDistance( $value){ - return $this->_set(3, $value); + public function setDistance($value) + { + return $this->_set(3, $value); } - + /** - * Check if has a value + * Check if has a value. * - * @return boolean + * @return bool */ - public function hasElapsedTime(){ - return $this->_has(4); + public function hasElapsedTime() + { + return $this->_has(4); } - + /** - * Clear value + * Clear value. * * @return \routeguide\RouteSummary */ - public function clearElapsedTime(){ - return $this->_clear(4); + public function clearElapsedTime() + { + return $this->_clear(4); } - + /** - * Get value + * Get value. * * @return int */ - public function getElapsedTime(){ - return $this->_get(4); + public function getElapsedTime() + { + return $this->_get(4); } - + /** - * Set value + * Set value. * * @param int $value + * * @return \routeguide\RouteSummary */ - public function setElapsedTime( $value){ - return $this->_set(4, $value); + public function setElapsedTime($value) + { + return $this->_set(4, $value); } } } namespace routeguide { - class RouteGuideClient extends \Grpc\BaseStub { - - public function __construct($hostname, $opts) { - parent::__construct($hostname, $opts); - } + class RouteGuideClient extends \Grpc\BaseStub + { + public function __construct($hostname, $opts) + { + parent::__construct($hostname, $opts); + } /** * @param routeguide\Point $input */ - public function GetFeature(\routeguide\Point $argument, $metadata = array(), $options = array()) { - return $this->_simpleRequest('/routeguide.RouteGuide/GetFeature', $argument, '\routeguide\Feature::deserialize', $metadata, $options); + public function GetFeature(\routeguide\Point $argument, $metadata = array(), $options = array()) + { + return $this->_simpleRequest('/routeguide.RouteGuide/GetFeature', $argument, '\routeguide\Feature::deserialize', $metadata, $options); } /** * @param routeguide\Rectangle $input */ - public function ListFeatures($argument, $metadata = array(), $options = array()) { - return $this->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', $argument, '\routeguide\Feature::deserialize', $metadata, $options); + public function ListFeatures($argument, $metadata = array(), $options = array()) + { + return $this->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', $argument, '\routeguide\Feature::deserialize', $metadata, $options); } /** * @param routeguide\Point $input */ - public function RecordRoute($metadata = array()) { - return $this->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', '\routeguide\RouteSummary::deserialize', $metadata); + public function RecordRoute($metadata = array()) + { + return $this->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', '\routeguide\RouteSummary::deserialize', $metadata); } /** * @param routeguide\RouteNote $input */ - public function RouteChat($metadata = array()) { - return $this->_bidiRequest('/routeguide.RouteGuide/RouteChat', '\routeguide\RouteNote::deserialize', $metadata); + public function RouteChat($metadata = array()) + { + return $this->_bidiRequest('/routeguide.RouteGuide/RouteChat', '\routeguide\RouteNote::deserialize', $metadata); } } } diff --git a/examples/php/route_guide/route_guide_client.php b/examples/php/route_guide/route_guide_client.php index 2f9533be4b7..595dacd9870 100644 --- a/examples/php/route_guide/route_guide_client.php +++ b/examples/php/route_guide/route_guide_client.php @@ -32,48 +32,50 @@ * */ -require dirname(__FILE__) . '/../vendor/autoload.php'; -require dirname(__FILE__) . '/route_guide.php'; +require dirname(__FILE__).'/../vendor/autoload.php'; +require dirname(__FILE__).'/route_guide.php'; define('COORD_FACTOR', 1e7); $client = new routeguide\RouteGuideClient('localhost:50051', [ - 'credentials' => Grpc\ChannelCredentials::createInsecure() + 'credentials' => Grpc\ChannelCredentials::createInsecure(), ]); -function printFeature($feature) { - $name = $feature->getName(); - if (!$name) { - $name_str = "no feature"; - } else { - $name_str = "feature called $name"; - } - print sprintf("Found %s \n at %f, %f\n", $name_str, - $feature->getLocation()->getLatitude() / COORD_FACTOR, - $feature->getLocation()->getLongitude() / COORD_FACTOR); +function printFeature($feature) +{ + $name = $feature->getName(); + if (!$name) { + $name_str = 'no feature'; + } else { + $name_str = "feature called $name"; + } + echo sprintf("Found %s \n at %f, %f\n", $name_str, + $feature->getLocation()->getLatitude() / COORD_FACTOR, + $feature->getLocation()->getLongitude() / COORD_FACTOR); } /** * Run the getFeature demo. Calls getFeature with a point known to have a * feature and a point known not to have a feature. */ -function runGetFeature() { - print "Running GetFeature...\n"; - global $client; - - $point = new routeguide\Point(); - $points = array( - array(409146138, -746188906), - array(0, 0), - ); - - foreach ($points as $p) { - $point->setLatitude($p[0]); - $point->setLongitude($p[1]); - // make a unary grpc call - list($feature, $status) = $client->GetFeature($point)->wait(); - printFeature($feature); - } +function runGetFeature() +{ + echo "Running GetFeature...\n"; + global $client; + + $point = new routeguide\Point(); + $points = array( + array(409146138, -746188906), + array(0, 0), + ); + + foreach ($points as $p) { + $point->setLatitude($p[0]); + $point->setLongitude($p[1]); + // make a unary grpc call + list($feature, $status) = $client->GetFeature($point)->wait(); + printFeature($feature); + } } /** @@ -81,29 +83,30 @@ function runGetFeature() { * containing all of the features in the pre-generated * database. Prints each response as it comes in. */ -function runListFeatures() { - print "Running ListFeatures...\n"; - global $client; - - $lo_point = new routeguide\Point(); - $hi_point = new routeguide\Point(); - - $lo_point->setLatitude(400000000); - $lo_point->setLongitude(-750000000); - $hi_point->setLatitude(420000000); - $hi_point->setLongitude(-730000000); - - $rectangle = new routeguide\Rectangle(); - $rectangle->setLo($lo_point); - $rectangle->setHi($hi_point); - - // start the server streaming call - $call = $client->ListFeatures($rectangle); - // an iterator over the server streaming responses - $features = $call->responses(); - foreach ($features as $feature) { - printFeature($feature); - } +function runListFeatures() +{ + echo "Running ListFeatures...\n"; + global $client; + + $lo_point = new routeguide\Point(); + $hi_point = new routeguide\Point(); + + $lo_point->setLatitude(400000000); + $lo_point->setLongitude(-750000000); + $hi_point->setLatitude(420000000); + $hi_point->setLongitude(-730000000); + + $rectangle = new routeguide\Rectangle(); + $rectangle->setLo($lo_point); + $rectangle->setHi($hi_point); + + // start the server streaming call + $call = $client->ListFeatures($rectangle); + // an iterator over the server streaming responses + $features = $call->responses(); + foreach ($features as $feature) { + printFeature($feature); + } } /** @@ -111,96 +114,99 @@ function runListFeatures() { * pre-generated feature database with a variable delay in between. Prints * the statistics when they are sent from the server. */ -function runRecordRoute() { - print "Running RecordRoute...\n"; - global $client, $argv; - - // start the client streaming call - $call = $client->RecordRoute(); - - $db = json_decode(file_get_contents($argv[1]), true); - $num_points_in_db = count($db); - $num_points = 10; - for ($i = 0; $i < $num_points; $i++) { - $point = new routeguide\Point(); - $index = rand(0, $num_points_in_db - 1); - $lat = $db[$index]['location']['latitude']; - $long = $db[$index]['location']['longitude']; - $feature_name = $db[$index]['name']; - $point->setLatitude($lat); - $point->setLongitude($long); - print sprintf("Visiting point %f, %f,\n with feature name: %s\n", - $lat / COORD_FACTOR, $long / COORD_FACTOR, - $feature_name ? $feature_name : ''); - usleep(rand(300000, 800000)); - $call->write($point); - } - list($route_summary, $status) = $call->wait(); - print sprintf("Finished trip with %d points\nPassed %d features\n". - "Travelled %d meters\nIt took %d seconds\n", - $route_summary->getPointCount(), - $route_summary->getFeatureCount(), - $route_summary->getDistance(), - $route_summary->getElapsedTime()); +function runRecordRoute() +{ + echo "Running RecordRoute...\n"; + global $client, $argv; + + // start the client streaming call + $call = $client->RecordRoute(); + + $db = json_decode(file_get_contents($argv[1]), true); + $num_points_in_db = count($db); + $num_points = 10; + for ($i = 0; $i < $num_points; ++$i) { + $point = new routeguide\Point(); + $index = rand(0, $num_points_in_db - 1); + $lat = $db[$index]['location']['latitude']; + $long = $db[$index]['location']['longitude']; + $feature_name = $db[$index]['name']; + $point->setLatitude($lat); + $point->setLongitude($long); + echo sprintf("Visiting point %f, %f,\n with feature name: %s\n", + $lat / COORD_FACTOR, $long / COORD_FACTOR, + $feature_name ? $feature_name : ''); + usleep(rand(300000, 800000)); + $call->write($point); + } + list($route_summary, $status) = $call->wait(); + echo sprintf("Finished trip with %d points\nPassed %d features\n". + "Travelled %d meters\nIt took %d seconds\n", + $route_summary->getPointCount(), + $route_summary->getFeatureCount(), + $route_summary->getDistance(), + $route_summary->getElapsedTime()); } /** * Run the routeChat demo. Send some chat messages, and print any chat * messages that are sent from the server. */ -function runRouteChat() { - print "Running RouteChat...\n"; - global $client; - - // start the bidirectional streaming call - $call = $client->RouteChat(); - - $notes = array( - array(1, 1, 'first message'), - array(1, 2, 'second message'), - array(2, 1, 'third message'), - array(1, 1, 'fourth message'), - array(1, 1, 'fifth message'), - ); - - foreach ($notes as $n) { - $point = new routeguide\Point(); - $point->setLatitude($lat = $n[0]); - $point->setLongitude($long = $n[1]); - - $route_note = new routeguide\RouteNote(); - $route_note->setLocation($point); - $route_note->setMessage($message = $n[2]); - - print sprintf("Sending message: '%s' at (%d, %d)\n", - $message, $lat, $long); - // send a bunch of messages to the server - $call->write($route_note); - } - $call->writesDone(); - - // read from the server until there's no more - while ($route_note_reply = $call->read()) { - print sprintf("Previous left message at (%d, %d): '%s'\n", - $route_note_reply->getLocation()->getLatitude(), - $route_note_reply->getLocation()->getLongitude(), - $route_note_reply->getMessage()); +function runRouteChat() +{ + echo "Running RouteChat...\n"; + global $client; + + // start the bidirectional streaming call + $call = $client->RouteChat(); + + $notes = array( + array(1, 1, 'first message'), + array(1, 2, 'second message'), + array(2, 1, 'third message'), + array(1, 1, 'fourth message'), + array(1, 1, 'fifth message'), + ); + + foreach ($notes as $n) { + $point = new routeguide\Point(); + $point->setLatitude($lat = $n[0]); + $point->setLongitude($long = $n[1]); + + $route_note = new routeguide\RouteNote(); + $route_note->setLocation($point); + $route_note->setMessage($message = $n[2]); + + echo sprintf("Sending message: '%s' at (%d, %d)\n", + $message, $lat, $long); + // send a bunch of messages to the server + $call->write($route_note); + } + $call->writesDone(); + + // read from the server until there's no more + while ($route_note_reply = $call->read()) { + echo sprintf("Previous left message at (%d, %d): '%s'\n", + $route_note_reply->getLocation()->getLatitude(), + $route_note_reply->getLocation()->getLongitude(), + $route_note_reply->getMessage()); } } /** - * Run all of the demos in order + * Run all of the demos in order. */ -function main() { - runGetFeature(); - runListFeatures(); - runRecordRoute(); - runRouteChat(); +function main() +{ + runGetFeature(); + runListFeatures(); + runRecordRoute(); + runRouteChat(); } if (empty($argv[1])) { - print "Usage: php -d extension=grpc.so route_guide_client.php " . + echo 'Usage: php -d extension=grpc.so route_guide_client.php '. "\n"; - exit(1); + exit(1); } main(); From 803c7ff9734649c09d7de892530d57ed570be1fa Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 19 May 2016 16:51:49 -0700 Subject: [PATCH 04/20] php: one little thing missed --- examples/php/route_guide/route_guide_client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/php/route_guide/route_guide_client.php b/examples/php/route_guide/route_guide_client.php index 595dacd9870..b3cd6067972 100644 --- a/examples/php/route_guide/route_guide_client.php +++ b/examples/php/route_guide/route_guide_client.php @@ -190,7 +190,7 @@ function runRouteChat() $route_note_reply->getLocation()->getLatitude(), $route_note_reply->getLocation()->getLongitude(), $route_note_reply->getMessage()); - } + } } /** From c045fd964559eed01e27f8f012cd74776b09ddf3 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Mon, 23 May 2016 12:05:54 -0700 Subject: [PATCH 05/20] Add a test for grpc/grpc#6522 --- .../grpcio/tests/unit/_cython/cygrpc_test.py | 284 ++++++++---------- .../tests/unit/_cython/test_utilities.py | 34 ++- 2 files changed, 153 insertions(+), 165 deletions(-) diff --git a/src/python/grpcio/tests/unit/_cython/cygrpc_test.py b/src/python/grpcio/tests/unit/_cython/cygrpc_test.py index 0a511101f0d..4039c1b99bd 100644 --- a/src/python/grpcio/tests/unit/_cython/cygrpc_test.py +++ b/src/python/grpcio/tests/unit/_cython/cygrpc_test.py @@ -143,22 +143,60 @@ class TypeSmokeTest(unittest.TestCase): del completion_queue -class InsecureServerInsecureClient(unittest.TestCase): +class ServerClientMixin(object): - def setUp(self): + def setUpMixin(self, server_credentials, client_credentials, host_override): self.server_completion_queue = cygrpc.CompletionQueue() self.server = cygrpc.Server() self.server.register_completion_queue(self.server_completion_queue) - self.port = self.server.add_http2_port('[::]:0') + if server_credentials: + self.port = self.server.add_http2_port('[::]:0', server_credentials) + else: + self.port = self.server.add_http2_port('[::]:0') self.server.start() self.client_completion_queue = cygrpc.CompletionQueue() - self.client_channel = cygrpc.Channel('localhost:{}'.format(self.port)) - - def tearDown(self): + if client_credentials: + client_channel_arguments = cygrpc.ChannelArgs([ + cygrpc.ChannelArg(cygrpc.ChannelArgKey.ssl_target_name_override, + host_override)]) + self.client_channel = cygrpc.Channel( + 'localhost:{}'.format(self.port), client_channel_arguments, + client_credentials) + else: + self.client_channel = cygrpc.Channel('localhost:{}'.format(self.port)) + if host_override: + self.host_argument = None # default host + self.expected_host = host_override + else: + # arbitrary host name necessitating no further identification + self.host_argument = b'hostess' + self.expected_host = self.host_argument + + def tearDownMixin(self): del self.server del self.client_completion_queue del self.server_completion_queue + def _perform_operations(self, operations, call, queue, deadline, description): + """Perform the list of operations with given call, queue, and deadline. + + Invocation errors are reported with as an exception with `description` in + the message. Performs the operations asynchronously, returning a future. + """ + def performer(): + tag = object() + try: + call_result = call.start_batch(cygrpc.Operations(operations), tag) + self.assertEqual(cygrpc.CallError.ok, call_result) + event = queue.poll(deadline) + self.assertEqual(cygrpc.CompletionType.operation_complete, event.type) + self.assertTrue(event.success) + self.assertIs(tag, event.tag) + except Exception as error: + raise Exception("Error in '{}': {}".format(description, error.message)) + return event + return test_utilities.SimpleFuture(performer) + def testEcho(self): DEADLINE = time.time()+5 DEADLINE_TOLERANCE = 0.25 @@ -175,7 +213,6 @@ class InsecureServerInsecureClient(unittest.TestCase): REQUEST = b'in death a member of project mayhem has a name' RESPONSE = b'his name is robert paulson' METHOD = b'twinkies' - HOST = b'hostess' cygrpc_deadline = cygrpc.Timespec(DEADLINE) @@ -188,7 +225,8 @@ class InsecureServerInsecureClient(unittest.TestCase): client_call_tag = object() client_call = self.client_channel.create_call( - None, 0, self.client_completion_queue, METHOD, HOST, cygrpc_deadline) + None, 0, self.client_completion_queue, METHOD, self.host_argument, + cygrpc_deadline) client_initial_metadata = cygrpc.Metadata([ cygrpc.Metadatum(CLIENT_METADATA_ASCII_KEY, CLIENT_METADATA_ASCII_VALUE), @@ -216,7 +254,8 @@ class InsecureServerInsecureClient(unittest.TestCase): test_common.metadata_transmitted(client_initial_metadata, request_event.request_metadata)) self.assertEqual(METHOD, request_event.request_call_details.method) - self.assertEqual(HOST, request_event.request_call_details.host) + self.assertEqual(self.expected_host, + request_event.request_call_details.host) self.assertLess( abs(DEADLINE - float(request_event.request_call_details.deadline)), DEADLINE_TOLERANCE) @@ -292,172 +331,101 @@ class InsecureServerInsecureClient(unittest.TestCase): del client_call del server_call - -class SecureServerSecureClient(unittest.TestCase): - - def setUp(self): - server_credentials = cygrpc.server_credentials_ssl( - None, [cygrpc.SslPemKeyCertPair(resources.private_key(), - resources.certificate_chain())], False) - channel_credentials = cygrpc.channel_credentials_ssl( - resources.test_root_certificates(), None) - self.server_completion_queue = cygrpc.CompletionQueue() - self.server = cygrpc.Server() - self.server.register_completion_queue(self.server_completion_queue) - self.port = self.server.add_http2_port('[::]:0', server_credentials) - self.server.start() - self.client_completion_queue = cygrpc.CompletionQueue() - client_channel_arguments = cygrpc.ChannelArgs([ - cygrpc.ChannelArg(cygrpc.ChannelArgKey.ssl_target_name_override, - _SSL_HOST_OVERRIDE)]) - self.client_channel = cygrpc.Channel( - 'localhost:{}'.format(self.port), client_channel_arguments, - channel_credentials) - - def tearDown(self): - del self.server - del self.client_completion_queue - del self.server_completion_queue - - def testEcho(self): + def test6522(self): DEADLINE = time.time()+5 DEADLINE_TOLERANCE = 0.25 - CLIENT_METADATA_ASCII_KEY = b'key' - CLIENT_METADATA_ASCII_VALUE = b'val' - CLIENT_METADATA_BIN_KEY = b'key-bin' - CLIENT_METADATA_BIN_VALUE = b'\0'*1000 - SERVER_INITIAL_METADATA_KEY = b'init_me_me_me' - SERVER_INITIAL_METADATA_VALUE = b'whodawha?' - SERVER_TRAILING_METADATA_KEY = b'california_is_in_a_drought' - SERVER_TRAILING_METADATA_VALUE = b'zomg it is' - SERVER_STATUS_CODE = cygrpc.StatusCode.ok - SERVER_STATUS_DETAILS = b'our work is never over' - REQUEST = b'in death a member of project mayhem has a name' - RESPONSE = b'his name is robert paulson' - METHOD = b'/twinkies' - HOST = None # Default host + METHOD = b'twinkies' cygrpc_deadline = cygrpc.Timespec(DEADLINE) + empty_metadata = cygrpc.Metadata([]) server_request_tag = object() - request_call_result = self.server.request_call( + self.server.request_call( self.server_completion_queue, self.server_completion_queue, server_request_tag) + client_call = self.client_channel.create_call( + None, 0, self.client_completion_queue, METHOD, self.host_argument, + cygrpc_deadline) - self.assertEqual(cygrpc.CallError.ok, request_call_result) - - plugin = cygrpc.CredentialsMetadataPlugin(_metadata_plugin_callback, '') - call_credentials = cygrpc.call_credentials_metadata_plugin(plugin) + # Prologue + def perform_client_operations(operations, description): + return self._perform_operations( + operations, client_call, + self.client_completion_queue, cygrpc_deadline, description) - client_call_tag = object() - client_call = self.client_channel.create_call( - None, 0, self.client_completion_queue, METHOD, HOST, cygrpc_deadline) - client_call.set_credentials(call_credentials) - client_initial_metadata = cygrpc.Metadata([ - cygrpc.Metadatum(CLIENT_METADATA_ASCII_KEY, - CLIENT_METADATA_ASCII_VALUE), - cygrpc.Metadatum(CLIENT_METADATA_BIN_KEY, CLIENT_METADATA_BIN_VALUE)]) - client_start_batch_result = client_call.start_batch(cygrpc.Operations([ - cygrpc.operation_send_initial_metadata(client_initial_metadata, - _EMPTY_FLAGS), - cygrpc.operation_send_message(REQUEST, _EMPTY_FLAGS), - cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), - cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS) - ]), client_call_tag) - self.assertEqual(cygrpc.CallError.ok, client_start_batch_result) - client_event_future = test_utilities.CompletionQueuePollFuture( - self.client_completion_queue, cygrpc_deadline) + client_event_future = perform_client_operations([ + cygrpc.operation_send_initial_metadata(empty_metadata, + _EMPTY_FLAGS), + cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), + ], "Client prologue") request_event = self.server_completion_queue.poll(cygrpc_deadline) - self.assertEqual(cygrpc.CompletionType.operation_complete, - request_event.type) - self.assertIsInstance(request_event.operation_call, cygrpc.Call) - self.assertIs(server_request_tag, request_event.tag) - self.assertEqual(0, len(request_event.batch_operations)) - client_metadata_with_credentials = list(client_initial_metadata) + [ - (_CALL_CREDENTIALS_METADATA_KEY, _CALL_CREDENTIALS_METADATA_VALUE)] - self.assertTrue( - test_common.metadata_transmitted(client_metadata_with_credentials, - request_event.request_metadata)) - self.assertEqual(METHOD, request_event.request_call_details.method) - self.assertEqual(_SSL_HOST_OVERRIDE, - request_event.request_call_details.host) - self.assertLess( - abs(DEADLINE - float(request_event.request_call_details.deadline)), - DEADLINE_TOLERANCE) - - server_call_tag = object() server_call = request_event.operation_call - server_initial_metadata = cygrpc.Metadata([ - cygrpc.Metadatum(SERVER_INITIAL_METADATA_KEY, - SERVER_INITIAL_METADATA_VALUE)]) - server_trailing_metadata = cygrpc.Metadata([ - cygrpc.Metadatum(SERVER_TRAILING_METADATA_KEY, - SERVER_TRAILING_METADATA_VALUE)]) - server_start_batch_result = server_call.start_batch([ - cygrpc.operation_send_initial_metadata(server_initial_metadata, - _EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - cygrpc.operation_send_message(RESPONSE, _EMPTY_FLAGS), - cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), - cygrpc.operation_send_status_from_server( - server_trailing_metadata, SERVER_STATUS_CODE, - SERVER_STATUS_DETAILS, _EMPTY_FLAGS) - ], server_call_tag) - self.assertEqual(cygrpc.CallError.ok, server_start_batch_result) - client_event = client_event_future.result() - server_event = self.server_completion_queue.poll(cygrpc_deadline) + def perform_server_operations(operations, description): + return self._perform_operations( + operations, server_call, + self.server_completion_queue, cygrpc_deadline, description) - self.assertEqual(6, len(client_event.batch_operations)) - found_client_op_types = set() - for client_result in client_event.batch_operations: - # we expect each op type to be unique - self.assertNotIn(client_result.type, found_client_op_types) - found_client_op_types.add(client_result.type) - if client_result.type == cygrpc.OperationType.receive_initial_metadata: - self.assertTrue( - test_common.metadata_transmitted(server_initial_metadata, - client_result.received_metadata)) - elif client_result.type == cygrpc.OperationType.receive_message: - self.assertEqual(RESPONSE, client_result.received_message.bytes()) - elif client_result.type == cygrpc.OperationType.receive_status_on_client: - self.assertTrue( - test_common.metadata_transmitted(server_trailing_metadata, - client_result.received_metadata)) - self.assertEqual(SERVER_STATUS_DETAILS, - client_result.received_status_details) - self.assertEqual(SERVER_STATUS_CODE, client_result.received_status_code) - self.assertEqual(set([ - cygrpc.OperationType.send_initial_metadata, - cygrpc.OperationType.send_message, - cygrpc.OperationType.send_close_from_client, - cygrpc.OperationType.receive_initial_metadata, - cygrpc.OperationType.receive_message, - cygrpc.OperationType.receive_status_on_client - ]), found_client_op_types) + server_event_future = perform_server_operations([ + cygrpc.operation_send_initial_metadata(empty_metadata, + _EMPTY_FLAGS), + ], "Server prologue") - self.assertEqual(5, len(server_event.batch_operations)) - found_server_op_types = set() - for server_result in server_event.batch_operations: - self.assertNotIn(client_result.type, found_server_op_types) - found_server_op_types.add(server_result.type) - if server_result.type == cygrpc.OperationType.receive_message: - self.assertEqual(REQUEST, server_result.received_message.bytes()) - elif server_result.type == cygrpc.OperationType.receive_close_on_server: - self.assertFalse(server_result.received_cancelled) - self.assertEqual(set([ - cygrpc.OperationType.send_initial_metadata, - cygrpc.OperationType.receive_message, - cygrpc.OperationType.send_message, - cygrpc.OperationType.receive_close_on_server, - cygrpc.OperationType.send_status_from_server - ]), found_server_op_types) + client_event_future.result() # force completion + server_event_future.result() - del client_call - del server_call + # Messaging + for _ in range(10): + client_event_future = perform_client_operations([ + cygrpc.operation_send_message(b'', _EMPTY_FLAGS), + cygrpc.operation_receive_message(_EMPTY_FLAGS), + ], "Client message") + server_event_future = perform_server_operations([ + cygrpc.operation_send_message(b'', _EMPTY_FLAGS), + cygrpc.operation_receive_message(_EMPTY_FLAGS), + ], "Server receive") + + client_event_future.result() # force completion + server_event_future.result() + + # Epilogue + client_event_future = perform_client_operations([ + cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), + cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS) + ], "Client epilogue") + + server_event_future = perform_server_operations([ + cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), + cygrpc.operation_send_status_from_server( + empty_metadata, cygrpc.StatusCode.ok, b'', _EMPTY_FLAGS) + ], "Server epilogue") + + client_event_future.result() # force completion + server_event_future.result() + + +class InsecureServerInsecureClient(unittest.TestCase, ServerClientMixin): + + def setUp(self): + self.setUpMixin(None, None, None) + + def tearDown(self): + self.tearDownMixin() + + +class SecureServerSecureClient(unittest.TestCase, ServerClientMixin): + + def setUp(self): + server_credentials = cygrpc.server_credentials_ssl( + None, [cygrpc.SslPemKeyCertPair(resources.private_key(), + resources.certificate_chain())], False) + client_credentials = cygrpc.channel_credentials_ssl( + resources.test_root_certificates(), None) + self.setUpMixin(server_credentials, client_credentials, _SSL_HOST_OVERRIDE) + + def tearDown(self): + self.tearDownMixin() if __name__ == '__main__': diff --git a/src/python/grpcio/tests/unit/_cython/test_utilities.py b/src/python/grpcio/tests/unit/_cython/test_utilities.py index 6a097396431..6280ce74c47 100644 --- a/src/python/grpcio/tests/unit/_cython/test_utilities.py +++ b/src/python/grpcio/tests/unit/_cython/test_utilities.py @@ -32,15 +32,35 @@ import threading from grpc._cython import cygrpc -class CompletionQueuePollFuture: +class SimpleFuture(object): + """A simple future mechanism.""" - def __init__(self, completion_queue, deadline): - def poller_function(): - self._event_result = completion_queue.poll(deadline) - self._event_result = None - self._thread = threading.Thread(target=poller_function) + def __init__(self, function, *args, **kwargs): + def wrapped_function(): + try: + self._result = function(*args, **kwargs) + except Exception as error: + self._error = error + self._result = None + self._error = None + self._thread = threading.Thread(target=wrapped_function) self._thread.start() def result(self): + """The resulting value of this future. + + Re-raises any exceptions. + """ self._thread.join() - return self._event_result + if self._error: + # TODO(atash): re-raise exceptions in a way that preserves tracebacks + raise self._error + return self._result + + +class CompletionQueuePollFuture(SimpleFuture): + + def __init__(self, completion_queue, deadline): + super(CompletionQueuePollFuture, self).__init__( + lambda: completion_queue.poll(deadline)) + From 6ae6fc7a797d1629fb8ceba4c5b8792f7c24c4a3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 1 Jun 2016 16:28:00 -0700 Subject: [PATCH 06/20] Fix server side memory leak If clients send GOAWAY followed by HEADER --- .../chttp2/transport/chttp2_transport.c | 6 +- .../23f261e44d54a2736f6e288128d98db9e5015206 | Bin 0 -> 100 bytes .../552199651d942e7220141a93ec33dd8256210a18 | Bin 0 -> 46 bytes .../7a946bf3cd91b63001f2cf3f40c515c747f2ecde | Bin 0 -> 696 bytes .../7d25c28298fb4d0fe41209d0d14307e4aa67c59e | Bin 0 -> 47 bytes .../8138b18a9a743659befc2f2b23d23cb9c3086a09 | Bin 0 -> 348 bytes .../925011abb99fd56bb0f425ae5e0d92e6d341f804 | Bin 0 -> 49 bytes ...h-c1f66840627e3bfdedf2e4c225bc4de0c267ed37 | Bin 0 -> 100 bytes .../d6bed9cc3c10338a8c5f41064ff8bec0bbc267ce | Bin 0 -> 48 bytes .../dda9643679f8c8b796e64232a7d153e447d64991 | Bin 0 -> 650 bytes .../e7b08e36420fa107f0aee652e62158af85a4ef15 | Bin 0 -> 1091 bytes tools/run_tests/tests.json | 170 ++++++++++++++++++ 12 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/23f261e44d54a2736f6e288128d98db9e5015206 create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/552199651d942e7220141a93ec33dd8256210a18 create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/7a946bf3cd91b63001f2cf3f40c515c747f2ecde create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/7d25c28298fb4d0fe41209d0d14307e4aa67c59e create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/8138b18a9a743659befc2f2b23d23cb9c3086a09 create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/925011abb99fd56bb0f425ae5e0d92e6d341f804 create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/crash-c1f66840627e3bfdedf2e4c225bc4de0c267ed37 create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/d6bed9cc3c10338a8c5f41064ff8bec0bbc267ce create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/dda9643679f8c8b796e64232a7d153e447d64991 create mode 100644 test/core/end2end/fuzzers/server_fuzzer_corpus/e7b08e36420fa107f0aee652e62158af85a4ef15 diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index b6886a2201b..d531d215e9d 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -804,8 +804,10 @@ void grpc_chttp2_add_incoming_goaway( gpr_free(msg); gpr_slice_unref(goaway_text); transport_global->seen_goaway = 1; - connectivity_state_set(exec_ctx, transport_global, GRPC_CHANNEL_FATAL_FAILURE, - "got_goaway"); + /* lie: use transient failure from the transport to indicate goaway has been + * received */ + connectivity_state_set(exec_ctx, transport_global, + GRPC_CHANNEL_TRANSIENT_FAILURE, "got_goaway"); } static void maybe_start_some_streams( diff --git a/test/core/end2end/fuzzers/server_fuzzer_corpus/23f261e44d54a2736f6e288128d98db9e5015206 b/test/core/end2end/fuzzers/server_fuzzer_corpus/23f261e44d54a2736f6e288128d98db9e5015206 new file mode 100644 index 0000000000000000000000000000000000000000..1452256ec7f7ec1680e657f27704cebbd1f0e69a GIT binary patch literal 100 zcmWFt@>I}L@CXSB&^OXE;N{}w3ibt&3=9k`Knwzsj35@H08e^RL9%X1W^QVJX$hC1 buR(rsYKlT~F-!$BnhFzz;?(5)yp&=9a@-X& literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/server_fuzzer_corpus/552199651d942e7220141a93ec33dd8256210a18 b/test/core/end2end/fuzzers/server_fuzzer_corpus/552199651d942e7220141a93ec33dd8256210a18 new file mode 100644 index 0000000000000000000000000000000000000000..c8c54f443d7d31d3d2032246c16aa4ecee8999c7 GIT binary patch literal 46 vcmWFt@>I}L@CXSB&^OXE;N{}w3ibt&3=9k%EI@*RL6d=<5yWErZ`A+*u!RQ9 literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/server_fuzzer_corpus/7a946bf3cd91b63001f2cf3f40c515c747f2ecde b/test/core/end2end/fuzzers/server_fuzzer_corpus/7a946bf3cd91b63001f2cf3f40c515c747f2ecde new file mode 100644 index 0000000000000000000000000000000000000000..8ef1b0ad7e9b1b0296610b941a573b75fe88bdef GIT binary patch literal 696 zcmcgqO;5ux40Wa;MqyG8aHiq}Xl*x+yNn|o5Ea`W$kMEhlqFH?N{oNYf8dA&Y1s$b zkl;k5JlWB+WBWOMx(~0zyXiDdZsI{N=mnF91_6Nj>rV#=y#*lbVB|O!-DGZUGUFvX z995!_3rPz^=e>o*!e%s`Oj$7EwRcK|%Ohltnd8*5M1{Y3yu{7R5;{7PY0^G7c_ZAAW(dz1EW#>eXXz&`)}w%Q`F20j7h CKz`Ez literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/server_fuzzer_corpus/7d25c28298fb4d0fe41209d0d14307e4aa67c59e b/test/core/end2end/fuzzers/server_fuzzer_corpus/7d25c28298fb4d0fe41209d0d14307e4aa67c59e new file mode 100644 index 0000000000000000000000000000000000000000..a323f7a1abda4f8abefe0567cf1dc458074b05fb GIT binary patch literal 47 xcmWFt@>I}L@CXSB&^OXE;N{}w3ibt&3=9k%EI@*RL6d=g%q_S!2dg~Lo2eG()fozg(g4rabQ?$Ofcc%sM9whvK>G+GuA>S5xZz$y0BhwtNj4ZsO}W4!by*j8))a31yhm6llKcRO C{$5)E literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/server_fuzzer_corpus/925011abb99fd56bb0f425ae5e0d92e6d341f804 b/test/core/end2end/fuzzers/server_fuzzer_corpus/925011abb99fd56bb0f425ae5e0d92e6d341f804 new file mode 100644 index 0000000000000000000000000000000000000000..948d5fafa33dd00337d84bfac9cd398ff5b479d1 GIT binary patch literal 49 zcmWFt@>I}L@CXSB&^OXE;N{}w3ibt&3=9k%EI@*RL6d=I}L@CXSB&^OXE;N{}w3ibt&3=9k`Knwzs>>w7S08e^RL9%X1W^QVJX$hC1 euR(rsYKlT~F;E2~NCh*R3KNCm)a3lUlwtsMTopM0 literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/server_fuzzer_corpus/d6bed9cc3c10338a8c5f41064ff8bec0bbc267ce b/test/core/end2end/fuzzers/server_fuzzer_corpus/d6bed9cc3c10338a8c5f41064ff8bec0bbc267ce new file mode 100644 index 0000000000000000000000000000000000000000..2b3424a332f810bbcc6519bc6a07ca4d729b8b0e GIT binary patch literal 48 ycmWFt@>I}L@CXSB&^OXE;N{}w3ibt&3=9k%EI@*RL6d==6^7rU{H$V1xk?(f$F~xyF`U+e$7{Q}MGIk%|-O(DEs9 zl23kTzbD^2=TG<1Wpp>4=E?Oq4Ts@y^3Y{Mi0_t*0r9$>NB1(zPz1@`m}JH(dXUvz zzyf@MXdPMr3RC#`<77&Q8EYJ>B({gjaHd3ABR%FuBWR4VwLqD*N^*wM=%lPHrzc&G z8RuXz2F*<&b$MFATrq@^EF5!$awXf+(g8w%6_X08nuI-Z!|=hSO z%~%n0C7pWI>+mEUUpX_zX>_inZk8A1=CyOe>(X{)+t8u)M|?W?N8zY{SB(st+T%Y7 vg=8O=7C4g5yP)?>KDS>`{xn8km>S;)xGO<-3tRYi7jFCeBI&;cF`B#q0jGhB literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/server_fuzzer_corpus/e7b08e36420fa107f0aee652e62158af85a4ef15 b/test/core/end2end/fuzzers/server_fuzzer_corpus/e7b08e36420fa107f0aee652e62158af85a4ef15 new file mode 100644 index 0000000000000000000000000000000000000000..523c785612efbb325e6812d8beac59ad13bc6832 GIT binary patch literal 1091 zcmcIjJ#WG=5H*mNkQT{9yGNZ`L`Y~mWnpcHs!`z&7{?@*LTn|61pRsaO^h9CCxV8r z0z)n3LsNfL`3@HG`FsAtY{Az2I999-1&b09Fw z8_%9cnS^zQ+f{~c$R-H^){Q>7#C2dMWP~Ry%ds`fS>}*PVcv~N=+K0#ZE&=wIx2dq z;R|09h)s7QggYjg>LRBxtMqgNR-?ok=&Pqw0Ez-kq)a#^z(wk6dhty`GNGGHtO!^$ z@+T9OlKTfny4-BP!kt|dKwYobS9<7q_I<+B+57vik&TIUY5SpPfLsLmGcg=*7wF?Y0WJg PQzTNPy?jUzzaIYqHu%$T literal 0 HcmV?d00001 diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 850f9474aec..c171d053547 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -70513,6 +70513,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/23f261e44d54a2736f6e288128d98db9e5015206" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/2463aea879c5ab49f8409d0e5c062c7e086b034b" @@ -71941,6 +71958,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/552199651d942e7220141a93ec33dd8256210a18" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/55af20415ead0ddd417f37fa91a4c767b749ee34" @@ -72706,6 +72740,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/7a946bf3cd91b63001f2cf3f40c515c747f2ecde" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/7b453adcb9c4bf31dbc448ff32c2bc90ebcbdf0f" @@ -72723,6 +72774,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/7d25c28298fb4d0fe41209d0d14307e4aa67c59e" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/7ddfac7d7845b424bf670070781ca6ff8586c63b" @@ -72774,6 +72842,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/8138b18a9a743659befc2f2b23d23cb9c3086a09" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/8164d3c4af043c47cfd6966873bccd2353d072bf" @@ -73182,6 +73267,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/925011abb99fd56bb0f425ae5e0d92e6d341f804" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/93beeba2.bin" @@ -74593,6 +74695,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/crash-c1f66840627e3bfdedf2e4c225bc4de0c267ed37" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/crash-dae0f07934a527989f23f06e630710ff6ca8c809" @@ -74695,6 +74814,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/d6bed9cc3c10338a8c5f41064ff8bec0bbc267ce" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/d8a1d141a9e3876b71c7decbe6e3affccf6de397" @@ -74848,6 +74984,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/dda9643679f8c8b796e64232a7d153e447d64991" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/df5d3cf5f05eab65ef9d385e263780ae73c42b19" @@ -74950,6 +75103,23 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/server_fuzzer_corpus/e7b08e36420fa107f0aee652e62158af85a4ef15" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "server_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/server_fuzzer_corpus/e96ad9c17795e52edc810a08d4fc61fe8790002a" From a9d8c5564e37e2d42fa3a6f4546ac3507b1b03c8 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Thu, 2 Jun 2016 16:11:28 -0700 Subject: [PATCH 07/20] Provide reasons in error messages when streams are canceled with a connection drop --- .../chttp2/transport/chttp2_transport.c | 74 ++++++++++++++++--- .../ext/transport/chttp2/transport/internal.h | 3 + 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index b6886a2201b..52ac895271e 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -47,6 +47,7 @@ #include "src/core/ext/transport/chttp2/transport/internal.h" #include "src/core/ext/transport/chttp2/transport/status_conversion.h" #include "src/core/ext/transport/chttp2/transport/timeout_encoding.h" +#include "src/core/lib/http/parser.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" @@ -107,7 +108,8 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, static void cancel_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global, - grpc_status_code status); + grpc_status_code status, + gpr_slice *optional_message); static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global, @@ -161,6 +163,8 @@ static void destruct_transport(grpc_exec_ctx *exec_ctx, GPR_ASSERT(t->ep == NULL); + gpr_slice_unref(t->optional_drop_message); + gpr_slice_buffer_destroy(&t->global.qbuf); gpr_slice_buffer_destroy(&t->writing.outbuf); @@ -260,6 +264,7 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, t->parsing.deframe_state = is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0; t->writing.is_client = is_client; + t->optional_drop_message = gpr_empty_slice(); grpc_connectivity_state_init( &t->channel_callback.state_tracker, GRPC_CHANNEL_READY, is_client ? "client_transport" : "server_transport"); @@ -859,7 +864,7 @@ static void maybe_start_some_streams( grpc_chttp2_list_pop_waiting_for_concurrency(transport_global, &stream_global)) { cancel_from_api(exec_ctx, transport_global, stream_global, - GRPC_STATUS_UNAVAILABLE); + GRPC_STATUS_UNAVAILABLE, NULL); } } @@ -936,7 +941,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, if (op->cancel_with_status != GRPC_STATUS_OK) { cancel_from_api(exec_ctx, transport_global, stream_global, - op->cancel_with_status); + op->cancel_with_status, op->optional_close_message); } if (op->close_with_status != GRPC_STATUS_OK) { @@ -960,7 +965,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, "(%lu vs. %lu)", metadata_size, metadata_peer_limit); cancel_from_api(exec_ctx, transport_global, stream_global, - GRPC_STATUS_RESOURCE_EXHAUSTED); + GRPC_STATUS_RESOURCE_EXHAUSTED, NULL); } else { if (contains_non_ok_status(transport_global, op->send_initial_metadata)) { stream_global->seen_error = true; @@ -1015,7 +1020,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, "(%lu vs. %lu)", metadata_size, metadata_peer_limit); cancel_from_api(exec_ctx, transport_global, stream_global, - GRPC_STATUS_RESOURCE_EXHAUSTED); + GRPC_STATUS_RESOURCE_EXHAUSTED, NULL); } else { if (contains_non_ok_status(transport_global, op->send_trailing_metadata)) { @@ -1201,7 +1206,7 @@ static void check_read_ops(grpc_exec_ctx *exec_ctx, } if (stream_global->exceeded_metadata_size) { cancel_from_api(exec_ctx, transport_global, stream_global, - GRPC_STATUS_RESOURCE_EXHAUSTED); + GRPC_STATUS_RESOURCE_EXHAUSTED, NULL); } } grpc_chttp2_incoming_metadata_buffer_publish( @@ -1240,7 +1245,7 @@ static void check_read_ops(grpc_exec_ctx *exec_ctx, } if (stream_global->exceeded_metadata_size) { cancel_from_api(exec_ctx, transport_global, stream_global, - GRPC_STATUS_RESOURCE_EXHAUSTED); + GRPC_STATUS_RESOURCE_EXHAUSTED, NULL); } } if (stream_global->all_incoming_byte_streams_finished) { @@ -1303,7 +1308,8 @@ static void remove_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, static void cancel_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global, - grpc_status_code status) { + grpc_status_code status, + gpr_slice *optional_message) { if (!stream_global->read_closed || !stream_global->write_closed) { if (stream_global->id != 0) { gpr_slice_buffer_add( @@ -1313,8 +1319,12 @@ static void cancel_from_api(grpc_exec_ctx *exec_ctx, (uint32_t)grpc_chttp2_grpc_status_to_http2_error(status), &stream_global->stats.outgoing)); } + + if (optional_message) { + gpr_slice_ref(*optional_message); + } grpc_chttp2_fake_status(exec_ctx, transport_global, stream_global, status, - NULL); + optional_message); } if (status != GRPC_STATUS_OK && !stream_global->seen_error) { stream_global->seen_error = true; @@ -1519,16 +1529,23 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, 1); } +typedef struct { + grpc_exec_ctx *exec_ctx; + gpr_slice optional_drop_message; +} cancel_stream_cb_arg; + static void cancel_stream_cb(grpc_chttp2_transport_global *transport_global, void *user_data, grpc_chttp2_stream_global *stream_global) { - cancel_from_api(user_data, transport_global, stream_global, - GRPC_STATUS_UNAVAILABLE); + cancel_stream_cb_arg *arg = user_data; + cancel_from_api(arg->exec_ctx, transport_global, stream_global, + GRPC_STATUS_UNAVAILABLE, &arg->optional_drop_message); } static void end_all_the_calls(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { - grpc_chttp2_for_all_streams(&t->global, exec_ctx, cancel_stream_cb); + cancel_stream_cb_arg arg = {exec_ctx, t->optional_drop_message}; + grpc_chttp2_for_all_streams(&t->global, &arg, cancel_stream_cb); } static void drop_connection(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { @@ -1599,6 +1616,31 @@ static void reading_action_locked(grpc_exec_ctx *exec_ctx, } } +static bool try_http_parsing(grpc_exec_ctx *exec_ctx, + grpc_chttp2_transport *t) { + return false; + grpc_http_parser parser; + size_t i = 0; + bool success = false; + + grpc_http_parser_init(&parser); + grpc_http1_trace = 1; + + for (; i < t->read_buffer.count && + grpc_http_parser_parse(&parser, t->read_buffer.slices[i]); + i++) + ; + if (grpc_http_parser_eof(&parser) && parser.type == GRPC_HTTP_RESPONSE) { + success = true; + GRPC_CHTTP2_IF_TRACING(gpr_log( + GPR_DEBUG, "Trying to connect an http1.x server, received status:%d", + parser.http.response.status)); + } + + grpc_http_parser_destroy(&parser); + return success; +} + static void parsing_action(grpc_exec_ctx *exec_ctx, void *arg, bool success) { grpc_chttp2_transport *t = arg; GPR_TIMER_BEGIN("reading_action.parse", 0); @@ -1610,6 +1652,14 @@ static void parsing_action(grpc_exec_ctx *exec_ctx, void *arg, bool success) { ; if (i != t->read_buffer.count) { success = false; + gpr_slice_unref(t->optional_drop_message); + if (try_http_parsing(exec_ctx, t)) { + t->optional_drop_message = gpr_slice_from_copied_string( + "Connection dropped: received http1.x response"); + } else { + t->optional_drop_message = gpr_slice_from_copied_string( + "Connection dropped: received unparseable response"); + } } GPR_TIMER_END("reading_action.parse", 0); grpc_chttp2_run_with_global_lock(exec_ctx, t, NULL, post_parse_locked, diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 5872fd8e0a4..7f3339a6204 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -383,6 +383,9 @@ struct grpc_chttp2_transport { /** Transport op to be applied post-parsing */ grpc_transport_op *post_parsing_op; + + /** Message explaining the reason of dropping connection */ + gpr_slice optional_drop_message; }; typedef struct { From 82ec451c427c0275964ee444d11238b07efeb94d Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Thu, 2 Jun 2016 18:34:34 -0700 Subject: [PATCH 08/20] Check if optional_drop_message is an empty slice --- .../ext/transport/chttp2/transport/chttp2_transport.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 52ac895271e..d0c94e6c463 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1531,7 +1531,7 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, typedef struct { grpc_exec_ctx *exec_ctx; - gpr_slice optional_drop_message; + gpr_slice *optional_drop_message; } cancel_stream_cb_arg; static void cancel_stream_cb(grpc_chttp2_transport_global *transport_global, @@ -1539,12 +1539,15 @@ static void cancel_stream_cb(grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global) { cancel_stream_cb_arg *arg = user_data; cancel_from_api(arg->exec_ctx, transport_global, stream_global, - GRPC_STATUS_UNAVAILABLE, &arg->optional_drop_message); + GRPC_STATUS_UNAVAILABLE, arg->optional_drop_message); } static void end_all_the_calls(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { - cancel_stream_cb_arg arg = {exec_ctx, t->optional_drop_message}; + cancel_stream_cb_arg arg = {exec_ctx, + GPR_SLICE_IS_EMPTY(t->optional_drop_message) + ? NULL + : &t->optional_drop_message}; grpc_chttp2_for_all_streams(&t->global, &arg, cancel_stream_cb); } @@ -1618,13 +1621,11 @@ static void reading_action_locked(grpc_exec_ctx *exec_ctx, static bool try_http_parsing(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { - return false; grpc_http_parser parser; size_t i = 0; bool success = false; grpc_http_parser_init(&parser); - grpc_http1_trace = 1; for (; i < t->read_buffer.count && grpc_http_parser_parse(&parser, t->read_buffer.slices[i]); From 9d69e8082d3af7c79b7402a546f8bea255bc69e3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 6 Jun 2016 11:37:50 -0700 Subject: [PATCH 09/20] Advertise transport selected in user-agent string --- src/core/lib/channel/channel_stack.c | 2 ++ src/core/lib/channel/channel_stack.h | 3 +++ src/core/lib/channel/channel_stack_builder.c | 4 ++-- src/core/lib/channel/http_client_filter.c | 13 +++++++++---- src/core/lib/channel/http_client_filter.h | 2 +- test/core/channel/channel_stack_test.c | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/core/lib/channel/channel_stack.c b/src/core/lib/channel/channel_stack.c index ad182d1f69f..224dd39d9b5 100644 --- a/src/core/lib/channel/channel_stack.c +++ b/src/core/lib/channel/channel_stack.c @@ -106,6 +106,7 @@ void grpc_channel_stack_init(grpc_exec_ctx *exec_ctx, int initial_refs, const grpc_channel_filter **filters, size_t filter_count, const grpc_channel_args *channel_args, + grpc_transport *optional_transport, const char *name, grpc_channel_stack *stack) { size_t call_size = ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call_stack)) + @@ -127,6 +128,7 @@ void grpc_channel_stack_init(grpc_exec_ctx *exec_ctx, int initial_refs, for (i = 0; i < filter_count; i++) { args.channel_stack = stack; args.channel_args = channel_args; + args.optional_transport = optional_transport; args.is_first = i == 0; args.is_last = i == (filter_count - 1); elems[i].filter = filters[i]; diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index 36c17cb467f..88fbe7a968d 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -57,6 +57,8 @@ typedef struct grpc_call_stack grpc_call_stack; typedef struct { grpc_channel_stack *channel_stack; const grpc_channel_args *channel_args; + /** Transport, iff it is known */ + grpc_transport *optional_transport; int is_first; int is_last; } grpc_channel_element_args; @@ -187,6 +189,7 @@ void grpc_channel_stack_init(grpc_exec_ctx *exec_ctx, int initial_refs, grpc_iomgr_cb_func destroy, void *destroy_arg, const grpc_channel_filter **filters, size_t filter_count, const grpc_channel_args *args, + grpc_transport *optional_transport, const char *name, grpc_channel_stack *stack); /* Destroy a channel stack */ void grpc_channel_stack_destroy(grpc_exec_ctx *exec_ctx, diff --git a/src/core/lib/channel/channel_stack_builder.c b/src/core/lib/channel/channel_stack_builder.c index a8646c95657..eda4968f486 100644 --- a/src/core/lib/channel/channel_stack_builder.c +++ b/src/core/lib/channel/channel_stack_builder.c @@ -257,8 +257,8 @@ void *grpc_channel_stack_builder_finish(grpc_exec_ctx *exec_ctx, // and initialize it grpc_channel_stack_init(exec_ctx, initial_refs, destroy, destroy_arg == NULL ? result : destroy_arg, filters, - num_filters, builder->args, builder->name, - channel_stack); + num_filters, builder->args, builder->transport, + builder->name, channel_stack); // run post-initialization functions i = 0; diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 516e708d1f0..55e87cd67c7 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -38,6 +38,7 @@ #include "src/core/lib/profiling/timers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" +#include "src/core/lib/transport/transport_impl.h" typedef struct call_data { grpc_linked_mdelem method; @@ -179,7 +180,8 @@ static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) { return GRPC_MDELEM_SCHEME_HTTP; } -static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args) { +static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args, + const char *transport_name) { gpr_strvec v; size_t i; int is_first = 1; @@ -201,8 +203,8 @@ static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args) { } } - gpr_asprintf(&tmp, "%sgrpc-c/%s (%s)", is_first ? "" : " ", - grpc_version_string(), GPR_PLATFORM_STRING); + gpr_asprintf(&tmp, "%sgrpc-c/%s (%s; %s)", is_first ? "" : " ", + grpc_version_string(), GPR_PLATFORM_STRING, transport_name); is_first = 0; gpr_strvec_add(&v, tmp); @@ -233,9 +235,12 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx, grpc_channel_element_args *args) { channel_data *chand = elem->channel_data; GPR_ASSERT(!args->is_last); + GPR_ASSERT(args->optional_transport != NULL); chand->static_scheme = scheme_from_args(args->channel_args); chand->user_agent = grpc_mdelem_from_metadata_strings( - GRPC_MDSTR_USER_AGENT, user_agent_from_args(args->channel_args)); + GRPC_MDSTR_USER_AGENT, + user_agent_from_args(args->channel_args, + args->optional_transport->vtable->name)); } /* Destructor for channel data */ diff --git a/src/core/lib/channel/http_client_filter.h b/src/core/lib/channel/http_client_filter.h index a884b36318a..47081175ea9 100644 --- a/src/core/lib/channel/http_client_filter.h +++ b/src/core/lib/channel/http_client_filter.h @@ -1,5 +1,4 @@ /* - * * Copyright 2015, Google Inc. * All rights reserved. * @@ -39,6 +38,7 @@ /* Processes metadata on the client side for HTTP2 transports */ extern const grpc_channel_filter grpc_http_client_filter; +/* Channel arg to override the http2 :scheme header */ #define GRPC_ARG_HTTP2_SCHEME "grpc.http2_scheme" #endif /* GRPC_CORE_LIB_CHANNEL_HTTP_CLIENT_FILTER_H */ diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c index 1a5594bde86..2d7737a3b04 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.c @@ -123,7 +123,7 @@ static void test_create_channel_stack(void) { channel_stack = gpr_malloc(grpc_channel_stack_size(&filters, 1)); grpc_channel_stack_init(&exec_ctx, 1, free_channel, channel_stack, &filters, - 1, &chan_args, "test", channel_stack); + 1, &chan_args, NULL, "test", channel_stack); GPR_ASSERT(channel_stack->count == 1); channel_elem = grpc_channel_stack_element(channel_stack, 0); channel_data = (int *)channel_elem->channel_data; From a2bc0ccb500f0fffcdd263420133b4a0d0cbad2d Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Mon, 6 Jun 2016 16:21:59 -0700 Subject: [PATCH 10/20] Get transport from transport global Avoid introducing cancel_stream_cb_arg --- .../chttp2/transport/chttp2_transport.c | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index d0c94e6c463..43e9ca1ff56 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1529,26 +1529,20 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, 1); } -typedef struct { - grpc_exec_ctx *exec_ctx; - gpr_slice *optional_drop_message; -} cancel_stream_cb_arg; - static void cancel_stream_cb(grpc_chttp2_transport_global *transport_global, void *user_data, grpc_chttp2_stream_global *stream_global) { - cancel_stream_cb_arg *arg = user_data; - cancel_from_api(arg->exec_ctx, transport_global, stream_global, - GRPC_STATUS_UNAVAILABLE, arg->optional_drop_message); + grpc_chttp2_transport *transport = TRANSPORT_FROM_GLOBAL(transport_global); + cancel_from_api(user_data, transport_global, stream_global, + GRPC_STATUS_UNAVAILABLE, + GPR_SLICE_IS_EMPTY(transport->optional_drop_message) + ? NULL + : &transport->optional_drop_message); } static void end_all_the_calls(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { - cancel_stream_cb_arg arg = {exec_ctx, - GPR_SLICE_IS_EMPTY(t->optional_drop_message) - ? NULL - : &t->optional_drop_message}; - grpc_chttp2_for_all_streams(&t->global, &arg, cancel_stream_cb); + grpc_chttp2_for_all_streams(&t->global, exec_ctx, cancel_stream_cb); } static void drop_connection(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { From d4b4009c3773a31e5fe48fb6cc0a6f9d859781a4 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Mon, 6 Jun 2016 17:03:05 -0700 Subject: [PATCH 11/20] Use Python namespace packages Before, namespace packages would break in auditwheel due to a superfluous check (fixed in the commit referenced in the Dockerfiles). Now, the auditwheel used in the manylinux1-support Docker images can handle namespace packages, and we may thus use them. This should alleviate future user pain w.r.t. installation of grpcio-tools causing loss of grpcio files and vice versa (e.g. requiring a reinstall of grpcio following installation of grpcio-tools). --- setup.py | 3 +-- tools/distrib/python/grpcio_tools/setup.py | 3 +-- .../grpc_artifact_python_manylinux_x64/Dockerfile | 7 +++++++ .../grpc_artifact_python_manylinux_x86/Dockerfile | 7 +++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index f96824fa883..88f859246a8 100644 --- a/setup.py +++ b/setup.py @@ -234,8 +234,7 @@ setuptools.setup( ext_modules=CYTHON_EXTENSION_MODULES, packages=list(PACKAGES), package_dir=PACKAGE_DIRECTORIES, - # TODO(atash): Figure out why auditwheel doesn't like namespace packages. - #namespace_packages=['grpc'], + namespace_packages=['grpc'], package_data=PACKAGE_DATA, install_requires=INSTALL_REQUIRES, setup_requires=SETUP_REQUIRES, diff --git a/tools/distrib/python/grpcio_tools/setup.py b/tools/distrib/python/grpcio_tools/setup.py index 576f7ae32a5..bb08ceaadad 100644 --- a/tools/distrib/python/grpcio_tools/setup.py +++ b/tools/distrib/python/grpcio_tools/setup.py @@ -88,8 +88,7 @@ setuptools.setup( protoc_ext_module(), ]), packages=setuptools.find_packages('.'), - # TODO(atash): Figure out why auditwheel doesn't like namespace packages. - #namespace_packages=['grpc'], + namespace_packages=['grpc'], install_requires=[ 'protobuf>=3.0.0a3', ], diff --git a/tools/dockerfile/grpc_artifact_python_manylinux_x64/Dockerfile b/tools/dockerfile/grpc_artifact_python_manylinux_x64/Dockerfile index 3e31a2b623d..1d4e8e1a4a4 100644 --- a/tools/dockerfile/grpc_artifact_python_manylinux_x64/Dockerfile +++ b/tools/dockerfile/grpc_artifact_python_manylinux_x64/Dockerfile @@ -41,3 +41,10 @@ RUN /opt/python/cp27-cp27mu/bin/pip install cython RUN /opt/python/cp34-cp34m/bin/pip install cython RUN /opt/python/cp35-cp35m/bin/pip install cython +#################################################### +# Install auditwheel with fix for namespace packages +RUN git clone https://github.com/pypa/auditwheel /usr/local/src/auditwheel +RUN cd /usr/local/src/auditwheel && git checkout bf071b38c9fe78b025ea05c78b1cb61d7cb09939 +RUN /opt/python/cp35-cp35m/bin/pip install /usr/local/src/auditwheel +RUN rm /usr/local/bin/auditwheel +RUN cd /usr/local/bin && ln -s /opt/python/cp35-cp35m/bin/auditwheel diff --git a/tools/dockerfile/grpc_artifact_python_manylinux_x86/Dockerfile b/tools/dockerfile/grpc_artifact_python_manylinux_x86/Dockerfile index 5fe62c28b73..810499695ec 100644 --- a/tools/dockerfile/grpc_artifact_python_manylinux_x86/Dockerfile +++ b/tools/dockerfile/grpc_artifact_python_manylinux_x86/Dockerfile @@ -41,3 +41,10 @@ RUN /opt/python/cp27-cp27mu/bin/pip install cython RUN /opt/python/cp34-cp34m/bin/pip install cython RUN /opt/python/cp35-cp35m/bin/pip install cython +#################################################### +# Install auditwheel with fix for namespace packages +RUN git clone https://github.com/pypa/auditwheel /usr/local/src/auditwheel +RUN cd /usr/local/src/auditwheel && git checkout bf071b38c9fe78b025ea05c78b1cb61d7cb09939 +RUN /opt/python/cp35-cp35m/bin/pip install /usr/local/src/auditwheel +RUN rm /usr/local/bin/auditwheel +RUN cd /usr/local/bin && ln -s /opt/python/cp35-cp35m/bin/auditwheel From 000aa457dccfb684136635647ff42b1fce58073f Mon Sep 17 00:00:00 2001 From: yang-g Date: Tue, 7 Jun 2016 13:08:39 -0700 Subject: [PATCH 12/20] add a test with empty request --- test/cpp/end2end/end2end_test.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index f52aa52f39f..e3667cf26bd 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -1014,6 +1014,16 @@ TEST_P(ProxyEnd2endTest, SimpleRpc) { SendRpc(stub_.get(), 1, false); } +TEST_P(ProxyEnd2endTest, SimpleRpcWithEmptyMessages) { + ResetStub(); + EchoRequest request; + EchoResponse response; + + ClientContext context; + Status s = stub_->Echo(&context, request, &response); + EXPECT_TRUE(s.ok()); +} + TEST_P(ProxyEnd2endTest, MultipleRpcs) { ResetStub(); std::vector threads; From 2dbc217e5e3f44e4b2037601a7c21b650edaa066 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Tue, 7 Jun 2016 15:03:57 -0700 Subject: [PATCH 13/20] Add common proto files to Python grpcio-tools --- tools/distrib/python/check_grpcio_tools.py | 2 +- .../python/grpcio_tools/grpc/tools/protoc.py | 5 ++- .../python/grpcio_tools/protoc_lib_deps.py | 4 +++ tools/distrib/python/grpcio_tools/setup.py | 33 +++++++++++++++-- tools/distrib/python/make_grpcio_tools.py | 35 ++++++++++++++----- 5 files changed, 65 insertions(+), 14 deletions(-) diff --git a/tools/distrib/python/check_grpcio_tools.py b/tools/distrib/python/check_grpcio_tools.py index baf2ff4effb..80c63278f42 100755 --- a/tools/distrib/python/check_grpcio_tools.py +++ b/tools/distrib/python/check_grpcio_tools.py @@ -37,7 +37,7 @@ OUT_OF_DATE_MESSAGE = """file {} is out of date Have you called tools/distrib/python/make_grpcio_tools.py since upgrading protobuf?""" -check_protoc_lib_deps_content = make.get_deps(make.BAZEL_DEPS_PROTOC_LIB_QUERY) +check_protoc_lib_deps_content = make.get_deps() with open(make.GRPC_PYTHON_PROTOC_LIB_DEPS, 'r') as protoc_lib_deps_file: if protoc_lib_deps_file.read() != check_protoc_lib_deps_content: diff --git a/tools/distrib/python/grpcio_tools/grpc/tools/protoc.py b/tools/distrib/python/grpcio_tools/grpc/tools/protoc.py index b4dd0ecae2e..1c69e78920c 100644 --- a/tools/distrib/python/grpcio_tools/grpc/tools/protoc.py +++ b/tools/distrib/python/grpcio_tools/grpc/tools/protoc.py @@ -29,10 +29,13 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import pkg_resources import sys from grpc.tools import protoc_compiler if __name__ == '__main__': - protoc_compiler.run_main(sys.argv) + proto_include = pkg_resources.resource_filename('grpc.tools', '_proto') + protoc_compiler.run_main( + sys.argv + ['-I{}'.format(proto_include)]) diff --git a/tools/distrib/python/grpcio_tools/protoc_lib_deps.py b/tools/distrib/python/grpcio_tools/protoc_lib_deps.py index 135ac5cbb3b..cd4effa7ae8 100644 --- a/tools/distrib/python/grpcio_tools/protoc_lib_deps.py +++ b/tools/distrib/python/grpcio_tools/protoc_lib_deps.py @@ -30,3 +30,7 @@ # AUTO-GENERATED BY make_grpcio_tools.py! CC_FILES=['google/protobuf/compiler/zip_writer.cc', 'google/protobuf/compiler/subprocess.cc', 'google/protobuf/compiler/ruby/ruby_generator.cc', 'google/protobuf/compiler/python/python_generator.cc', 'google/protobuf/compiler/plugin.pb.cc', 'google/protobuf/compiler/plugin.cc', 'google/protobuf/compiler/objectivec/objectivec_primitive_field.cc', 'google/protobuf/compiler/objectivec/objectivec_oneof.cc', 'google/protobuf/compiler/objectivec/objectivec_message_field.cc', 'google/protobuf/compiler/objectivec/objectivec_message.cc', 'google/protobuf/compiler/objectivec/objectivec_map_field.cc', 'google/protobuf/compiler/objectivec/objectivec_helpers.cc', 'google/protobuf/compiler/objectivec/objectivec_generator.cc', 'google/protobuf/compiler/objectivec/objectivec_file.cc', 'google/protobuf/compiler/objectivec/objectivec_field.cc', 'google/protobuf/compiler/objectivec/objectivec_extension.cc', 'google/protobuf/compiler/objectivec/objectivec_enum_field.cc', 'google/protobuf/compiler/objectivec/objectivec_enum.cc', 'google/protobuf/compiler/js/js_generator.cc', 'google/protobuf/compiler/javanano/javanano_primitive_field.cc', 'google/protobuf/compiler/javanano/javanano_message_field.cc', 'google/protobuf/compiler/javanano/javanano_message.cc', 'google/protobuf/compiler/javanano/javanano_map_field.cc', 'google/protobuf/compiler/javanano/javanano_helpers.cc', 'google/protobuf/compiler/javanano/javanano_generator.cc', 'google/protobuf/compiler/javanano/javanano_file.cc', 'google/protobuf/compiler/javanano/javanano_field.cc', 'google/protobuf/compiler/javanano/javanano_extension.cc', 'google/protobuf/compiler/javanano/javanano_enum_field.cc', 'google/protobuf/compiler/javanano/javanano_enum.cc', 'google/protobuf/compiler/java/java_string_field_lite.cc', 'google/protobuf/compiler/java/java_string_field.cc', 'google/protobuf/compiler/java/java_shared_code_generator.cc', 'google/protobuf/compiler/java/java_service.cc', 'google/protobuf/compiler/java/java_primitive_field_lite.cc', 'google/protobuf/compiler/java/java_primitive_field.cc', 'google/protobuf/compiler/java/java_name_resolver.cc', 'google/protobuf/compiler/java/java_message_lite.cc', 'google/protobuf/compiler/java/java_message_field_lite.cc', 'google/protobuf/compiler/java/java_message_field.cc', 'google/protobuf/compiler/java/java_message_builder_lite.cc', 'google/protobuf/compiler/java/java_message_builder.cc', 'google/protobuf/compiler/java/java_message.cc', 'google/protobuf/compiler/java/java_map_field_lite.cc', 'google/protobuf/compiler/java/java_map_field.cc', 'google/protobuf/compiler/java/java_lazy_message_field_lite.cc', 'google/protobuf/compiler/java/java_lazy_message_field.cc', 'google/protobuf/compiler/java/java_helpers.cc', 'google/protobuf/compiler/java/java_generator_factory.cc', 'google/protobuf/compiler/java/java_generator.cc', 'google/protobuf/compiler/java/java_file.cc', 'google/protobuf/compiler/java/java_field.cc', 'google/protobuf/compiler/java/java_extension_lite.cc', 'google/protobuf/compiler/java/java_extension.cc', 'google/protobuf/compiler/java/java_enum_lite.cc', 'google/protobuf/compiler/java/java_enum_field_lite.cc', 'google/protobuf/compiler/java/java_enum_field.cc', 'google/protobuf/compiler/java/java_enum.cc', 'google/protobuf/compiler/java/java_doc_comment.cc', 'google/protobuf/compiler/java/java_context.cc', 'google/protobuf/compiler/csharp/csharp_wrapper_field.cc', 'google/protobuf/compiler/csharp/csharp_source_generator_base.cc', 'google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc', 'google/protobuf/compiler/csharp/csharp_repeated_message_field.cc', 'google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc', 'google/protobuf/compiler/csharp/csharp_reflection_class.cc', 'google/protobuf/compiler/csharp/csharp_primitive_field.cc', 'google/protobuf/compiler/csharp/csharp_message_field.cc', 'google/protobuf/compiler/csharp/csharp_message.cc', 'google/protobuf/compiler/csharp/csharp_map_field.cc', 'google/protobuf/compiler/csharp/csharp_helpers.cc', 'google/protobuf/compiler/csharp/csharp_generator.cc', 'google/protobuf/compiler/csharp/csharp_field_base.cc', 'google/protobuf/compiler/csharp/csharp_enum_field.cc', 'google/protobuf/compiler/csharp/csharp_enum.cc', 'google/protobuf/compiler/csharp/csharp_doc_comment.cc', 'google/protobuf/compiler/cpp/cpp_string_field.cc', 'google/protobuf/compiler/cpp/cpp_service.cc', 'google/protobuf/compiler/cpp/cpp_primitive_field.cc', 'google/protobuf/compiler/cpp/cpp_message_field.cc', 'google/protobuf/compiler/cpp/cpp_message.cc', 'google/protobuf/compiler/cpp/cpp_map_field.cc', 'google/protobuf/compiler/cpp/cpp_helpers.cc', 'google/protobuf/compiler/cpp/cpp_generator.cc', 'google/protobuf/compiler/cpp/cpp_file.cc', 'google/protobuf/compiler/cpp/cpp_field.cc', 'google/protobuf/compiler/cpp/cpp_extension.cc', 'google/protobuf/compiler/cpp/cpp_enum_field.cc', 'google/protobuf/compiler/cpp/cpp_enum.cc', 'google/protobuf/compiler/command_line_interface.cc', 'google/protobuf/compiler/code_generator.cc', 'google/protobuf/wrappers.pb.cc', 'google/protobuf/wire_format.cc', 'google/protobuf/util/type_resolver_util.cc', 'google/protobuf/util/time_util.cc', 'google/protobuf/util/message_differencer.cc', 'google/protobuf/util/json_util.cc', 'google/protobuf/util/internal/utility.cc', 'google/protobuf/util/internal/type_info_test_helper.cc', 'google/protobuf/util/internal/type_info.cc', 'google/protobuf/util/internal/protostream_objectwriter.cc', 'google/protobuf/util/internal/protostream_objectsource.cc', 'google/protobuf/util/internal/proto_writer.cc', 'google/protobuf/util/internal/object_writer.cc', 'google/protobuf/util/internal/json_stream_parser.cc', 'google/protobuf/util/internal/json_objectwriter.cc', 'google/protobuf/util/internal/json_escaping.cc', 'google/protobuf/util/internal/field_mask_utility.cc', 'google/protobuf/util/internal/error_listener.cc', 'google/protobuf/util/internal/default_value_objectwriter.cc', 'google/protobuf/util/internal/datapiece.cc', 'google/protobuf/util/field_mask_util.cc', 'google/protobuf/util/field_comparator.cc', 'google/protobuf/unknown_field_set.cc', 'google/protobuf/type.pb.cc', 'google/protobuf/timestamp.pb.cc', 'google/protobuf/text_format.cc', 'google/protobuf/stubs/substitute.cc', 'google/protobuf/stubs/mathlimits.cc', 'google/protobuf/struct.pb.cc', 'google/protobuf/source_context.pb.cc', 'google/protobuf/service.cc', 'google/protobuf/reflection_ops.cc', 'google/protobuf/message.cc', 'google/protobuf/map_field.cc', 'google/protobuf/io/zero_copy_stream_impl.cc', 'google/protobuf/io/tokenizer.cc', 'google/protobuf/io/strtod.cc', 'google/protobuf/io/printer.cc', 'google/protobuf/io/gzip_stream.cc', 'google/protobuf/generated_message_reflection.cc', 'google/protobuf/field_mask.pb.cc', 'google/protobuf/extension_set_heavy.cc', 'google/protobuf/empty.pb.cc', 'google/protobuf/dynamic_message.cc', 'google/protobuf/duration.pb.cc', 'google/protobuf/descriptor_database.cc', 'google/protobuf/descriptor.pb.cc', 'google/protobuf/descriptor.cc', 'google/protobuf/compiler/parser.cc', 'google/protobuf/compiler/importer.cc', 'google/protobuf/api.pb.cc', 'google/protobuf/any.pb.cc', 'google/protobuf/any.cc', 'google/protobuf/wire_format_lite.cc', 'google/protobuf/stubs/time.cc', 'google/protobuf/stubs/strutil.cc', 'google/protobuf/stubs/structurally_valid.cc', 'google/protobuf/stubs/stringprintf.cc', 'google/protobuf/stubs/stringpiece.cc', 'google/protobuf/stubs/statusor.cc', 'google/protobuf/stubs/status.cc', 'google/protobuf/stubs/once.cc', 'google/protobuf/stubs/int128.cc', 'google/protobuf/stubs/common.cc', 'google/protobuf/stubs/bytestream.cc', 'google/protobuf/stubs/atomicops_internals_x86_msvc.cc', 'google/protobuf/stubs/atomicops_internals_x86_gcc.cc', 'google/protobuf/repeated_field.cc', 'google/protobuf/message_lite.cc', 'google/protobuf/io/zero_copy_stream_impl_lite.cc', 'google/protobuf/io/zero_copy_stream.cc', 'google/protobuf/io/coded_stream.cc', 'google/protobuf/generated_message_util.cc', 'google/protobuf/extension_set.cc', 'google/protobuf/arenastring.cc', 'google/protobuf/arena.cc'] +PROTO_FILES=['google/protobuf/wrappers.proto', 'google/protobuf/type.proto', 'google/protobuf/timestamp.proto', 'google/protobuf/struct.proto', 'google/protobuf/source_context.proto', 'google/protobuf/field_mask.proto', 'google/protobuf/empty.proto', 'google/protobuf/duration.proto', 'google/protobuf/descriptor.proto', 'google/protobuf/compiler/plugin.proto', 'google/protobuf/api.proto', 'google/protobuf/any.proto'] + +CC_INCLUDE='third_party/protobuf/src' +PROTO_INCLUDE='third_party/protobuf/src' diff --git a/tools/distrib/python/grpcio_tools/setup.py b/tools/distrib/python/grpcio_tools/setup.py index 576f7ae32a5..6537c266b32 100644 --- a/tools/distrib/python/grpcio_tools/setup.py +++ b/tools/distrib/python/grpcio_tools/setup.py @@ -28,9 +28,11 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from distutils import extension +import errno import os import os.path import shlex +import shutil import sys import setuptools @@ -47,18 +49,41 @@ sys.path.insert(0, os.path.abspath('.')) # ourselves in w.r.t. the multitude of operating systems this ought to build on. # By default we assume a GCC-like compiler. EXTRA_COMPILE_ARGS = shlex.split(os.environ.get('GRPC_PYTHON_CFLAGS', - '-frtti -std=c++11')) + '-fno-wrapv -frtti -std=c++11')) EXTRA_LINK_ARGS = shlex.split(os.environ.get('GRPC_PYTHON_LDFLAGS', '-lpthread')) +GRPC_PYTHON_TOOLS_PACKAGE = 'grpc.tools' +GRPC_PYTHON_PROTO_RESOURCES_NAME = '_proto' + import protoc_lib_deps import grpc_version +def package_data(): + tools_path = GRPC_PYTHON_TOOLS_PACKAGE.replace('.', os.path.sep) + proto_resources_path = os.path.join(tools_path, + GRPC_PYTHON_PROTO_RESOURCES_NAME) + proto_files = [] + for proto_file in protoc_lib_deps.PROTO_FILES: + source = os.path.join(protoc_lib_deps.PROTO_INCLUDE, proto_file) + target = os.path.join(proto_resources_path, proto_file) + relative_target = os.path.join(GRPC_PYTHON_PROTO_RESOURCES_NAME, proto_file) + try: + os.makedirs(os.path.dirname(target)) + except OSError as error: + if error.errno == errno.EEXIST: + pass + else: + raise + shutil.copy(source, target) + proto_files.append(relative_target) + return {GRPC_PYTHON_TOOLS_PACKAGE: proto_files} + def protoc_ext_module(): plugin_sources = [ 'grpc/tools/main.cc', 'grpc_root/src/compiler/python_generator.cc'] + [ - os.path.join('third_party/protobuf/src', cc_file) + os.path.join(protoc_lib_deps.CC_INCLUDE, cc_file) for cc_file in protoc_lib_deps.CC_FILES] plugin_ext = extension.Extension( name='grpc.tools.protoc_compiler', @@ -67,7 +92,7 @@ def protoc_ext_module(): '.', 'grpc_root', 'grpc_root/include', - 'third_party/protobuf/src', + protoc_lib_deps.CC_INCLUDE, ], language='c++', define_macros=[('HAVE_PTHREAD', 1)], @@ -92,5 +117,7 @@ setuptools.setup( #namespace_packages=['grpc'], install_requires=[ 'protobuf>=3.0.0a3', + 'grpcio>=0.14.0', ], + package_data=package_data(), ) diff --git a/tools/distrib/python/make_grpcio_tools.py b/tools/distrib/python/make_grpcio_tools.py index 50fbdbb14c0..fd9b38b084b 100755 --- a/tools/distrib/python/make_grpcio_tools.py +++ b/tools/distrib/python/make_grpcio_tools.py @@ -67,11 +67,16 @@ DEPS_FILE_CONTENT=""" # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # AUTO-GENERATED BY make_grpcio_tools.py! -CC_FILES={} +CC_FILES={cc_files} +PROTO_FILES={proto_files} + +CC_INCLUDE={cc_include} +PROTO_INCLUDE={proto_include} """ # Bazel query result prefix for expected source files in protobuf. PROTOBUF_CC_PREFIX = '//:src/' +PROTOBUF_PROTO_PREFIX = '//:src/' GRPC_ROOT = os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -79,7 +84,8 @@ GRPC_ROOT = os.path.abspath( GRPC_PYTHON_ROOT = os.path.join(GRPC_ROOT, 'tools/distrib/python/grpcio_tools') -GRPC_PROTOBUF = os.path.join(GRPC_ROOT, 'third_party/protobuf/src') +GRPC_PYTHON_PROTOBUF_RELATIVE_ROOT = 'third_party/protobuf/src' +GRPC_PROTOBUF = os.path.join(GRPC_ROOT, GRPC_PYTHON_PROTOBUF_RELATIVE_ROOT) GRPC_PROTOC_PLUGINS = os.path.join(GRPC_ROOT, 'src/compiler') GRPC_PYTHON_PROTOBUF = os.path.join(GRPC_PYTHON_ROOT, 'third_party/protobuf/src') @@ -93,18 +99,29 @@ GRPC_PYTHON_INCLUDE = os.path.join(GRPC_PYTHON_ROOT, 'grpc_root/include') BAZEL_DEPS = os.path.join(GRPC_ROOT, 'tools/distrib/python/bazel_deps.sh') BAZEL_DEPS_PROTOC_LIB_QUERY = '//:protoc_lib' +BAZEL_DEPS_COMMON_PROTOS_QUERY = '//:well_known_protos' + +def bazel_query(query): + output = subprocess.check_output([BAZEL_DEPS, query]) + return output.splitlines() -def get_deps(query): +def get_deps(): """Write the result of the bazel query `query` against protobuf to `out_file`.""" - output = subprocess.check_output([BAZEL_DEPS, query]) - output = output.splitlines() + cc_files_output = bazel_query(BAZEL_DEPS_PROTOC_LIB_QUERY) cc_files = [ - name for name in output + name[len(PROTOBUF_CC_PREFIX):] for name in cc_files_output if name.endswith('.cc') and name.startswith(PROTOBUF_CC_PREFIX)] - cc_files = [cc_file[len(PROTOBUF_CC_PREFIX):] for cc_file in cc_files] - deps_file_content = DEPS_FILE_CONTENT.format(cc_files) + proto_files_output = bazel_query(BAZEL_DEPS_COMMON_PROTOS_QUERY) + proto_files = [ + name[len(PROTOBUF_PROTO_PREFIX):] for name in proto_files_output + if name.endswith('.proto') and name.startswith(PROTOBUF_PROTO_PREFIX)] + deps_file_content = DEPS_FILE_CONTENT.format( + cc_files=cc_files, + proto_files=proto_files, + cc_include=repr(GRPC_PYTHON_PROTOBUF_RELATIVE_ROOT), + proto_include=repr(GRPC_PYTHON_PROTOBUF_RELATIVE_ROOT)) return deps_file_content @@ -123,7 +140,7 @@ def main(): shutil.copytree(GRPC_INCLUDE, GRPC_PYTHON_INCLUDE) try: - protoc_lib_deps_content = get_deps(BAZEL_DEPS_PROTOC_LIB_QUERY) + protoc_lib_deps_content = get_deps() except Exception as error: # We allow this script to succeed even if we couldn't get the dependencies, # as then we can assume that even without a successful bazel run the From 95e547ef9ec96d7693c86d007555b5ce68be3510 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 7 Jun 2016 17:14:42 -0700 Subject: [PATCH 14/20] add unstarted server test --- src/csharp/Grpc.Core.Tests/ServerTest.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/csharp/Grpc.Core.Tests/ServerTest.cs b/src/csharp/Grpc.Core.Tests/ServerTest.cs index fa693162ada..5f7144611e5 100644 --- a/src/csharp/Grpc.Core.Tests/ServerTest.cs +++ b/src/csharp/Grpc.Core.Tests/ServerTest.cs @@ -93,5 +93,12 @@ namespace Grpc.Core.Tests server.ShutdownAsync().Wait(); } + + [Test] + public void UnstartedServerDoesNotPreventShutdown() + { + // just create a server, don't start it, and make sure it doesn't prevent shutdown. + var server = new Server(); + } } } From f6d09f2566561c9407c564a46901ff3a237ce115 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Tue, 7 Jun 2016 22:19:46 -0700 Subject: [PATCH 15/20] Fix command ordering for building Python artifacts Source packages were not getting the necessary C files due to `make_grpcio_tools.py` not being invoked before `sdist` through `setup.py`. --- tools/run_tests/build_artifact_python.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/run_tests/build_artifact_python.sh b/tools/run_tests/build_artifact_python.sh index 4320f978e30..55f8eb634ba 100755 --- a/tools/run_tests/build_artifact_python.sh +++ b/tools/run_tests/build_artifact_python.sh @@ -59,12 +59,14 @@ ${SETARCH_CMD} ${PYTHON} setup.py \ ${SETARCH_CMD} ${PYTHON} setup.py \ bdist_wheel +# Build gRPC tools package distribution +${PYTHON} tools/distrib/python/make_grpcio_tools.py + # Build gRPC tools package source distribution ${SETARCH_CMD} ${PYTHON} tools/distrib/python/grpcio_tools/setup.py \ sdist # Build gRPC tools package binary distribution -${PYTHON} tools/distrib/python/make_grpcio_tools.py CFLAGS="$CFLAGS -fno-wrapv" ${SETARCH_CMD} \ ${PYTHON} tools/distrib/python/grpcio_tools/setup.py bdist_wheel From cb79b29ac589ba0f17da1588430db4407f73b5f6 Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Wed, 8 Jun 2016 15:07:54 -0700 Subject: [PATCH 16/20] fix for issue 6344. added printing of .proto file comments in generated code. --- src/compiler/objective_c_generator.cc | 33 ++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index 71a674174d7..db0b61ee6f0 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -60,9 +60,34 @@ void PrintProtoRpcDeclarationAsPragma(Printer *printer, " returns ($server_stream$$response_type$)\n\n"); } +template +static void PrintAllComments(const DescriptorType* desc, Printer* printer) { + std::vector comments; + grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING_DETACHED, + &comments); + grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING, + &comments); + grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_TRAILING, + &comments); + if (comments.empty()) { + return; + } + printer->Print("/**\n"); + for (auto it = comments.begin(); it != comments.end(); ++it) { + printer->Print(" * "); + size_t start_pos = it->find_first_not_of(' '); + if (start_pos != grpc::string::npos) { + printer->Print(it->c_str() + start_pos); + } + printer->Print("\n"); + } + printer->Print(" */\n"); +} + void PrintMethodSignature(Printer *printer, const MethodDescriptor *method, const map< ::grpc::string, ::grpc::string> &vars) { - // TODO(jcanizales): Print method comments. + // Print comment + PrintAllComments(method, printer); printer->Print(vars, "- ($return_type$)$method_name$With"); if (method->client_streaming()) { @@ -195,8 +220,10 @@ void PrintMethodImplementations(Printer *printer, printer.Print("@end\n\n"); printer.Print( - "// Basic service implementation, over gRPC, that only does" - " marshalling and parsing.\n"); + "/**\n" + " * Basic service implementation, over gRPC, that only does\n" + " * marshalling and parsing.\n" + " */\n"); printer.Print(vars, "@interface $service_class$ :" " GRPCProtoService<$service_class$>\n"); From 82c3dd1f0a96944122d3a0e40242d592a2c7db64 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Wed, 8 Jun 2016 16:56:00 -0700 Subject: [PATCH 17/20] Add usage documentation to Python tools distribution --- tools/distrib/python/grpcio_tools/README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/distrib/python/grpcio_tools/README.rst b/tools/distrib/python/grpcio_tools/README.rst index 10d2fe8c309..e9f137493ba 100644 --- a/tools/distrib/python/grpcio_tools/README.rst +++ b/tools/distrib/python/grpcio_tools/README.rst @@ -126,3 +126,13 @@ Help, I ... GCC 6.0), this is probably a bug where GCC chokes on constant expressions when the :code:`-fwrapv` flag is specified. You should consider setting your environment with :code:`CFLAGS=-fno-wrapv` or using clang (:code:`CC=clang`). + +Usage +----- + +Given protobuf include directories :code:`$INCLUDE`, an output directory +:code:`$OUTPUT`, and proto files :code:`$PROTO_FILES`, invoke as: + +:: + + $ python -m grpc.tools.protoc -I$INCLUDE --python_out=$OUTPUT --grpc_python_out=$OUTPUT $PROTO_FILES From 8e93533f65938a83760f522c9825cd903a307f03 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 8 Jun 2016 19:45:54 -0700 Subject: [PATCH 18/20] allow shutdown of unstarted server --- src/csharp/Grpc.Core.Tests/ServerTest.cs | 8 ++++++++ src/csharp/Grpc.Core/Server.cs | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/csharp/Grpc.Core.Tests/ServerTest.cs b/src/csharp/Grpc.Core.Tests/ServerTest.cs index 5f7144611e5..3b51aa63300 100644 --- a/src/csharp/Grpc.Core.Tests/ServerTest.cs +++ b/src/csharp/Grpc.Core.Tests/ServerTest.cs @@ -94,6 +94,14 @@ namespace Grpc.Core.Tests server.ShutdownAsync().Wait(); } + [Test] + public void UnstartedServerCanBeShutdown() + { + var server = new Server(); + server.ShutdownAsync().Wait(); + Assert.Throws(typeof(InvalidOperationException), () => server.Start()); + } + [Test] public void UnstartedServerDoesNotPreventShutdown() { diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs index ae7a8c9a9a1..3b554e5e87e 100644 --- a/src/csharp/Grpc.Core/Server.cs +++ b/src/csharp/Grpc.Core/Server.cs @@ -140,6 +140,7 @@ namespace Grpc.Core lock (myLock) { GrpcPreconditions.CheckState(!startRequested); + GrpcPreconditions.CheckState(!shutdownRequested); startRequested = true; handle.Start(); @@ -203,7 +204,6 @@ namespace Grpc.Core { lock (myLock) { - GrpcPreconditions.CheckState(startRequested); GrpcPreconditions.CheckState(!shutdownRequested); shutdownRequested = true; } @@ -215,7 +215,6 @@ namespace Grpc.Core { handle.CancelAllCalls(); } - await ShutdownCompleteOrEnvironmentDeadAsync().ConfigureAwait(false); DisposeHandle(); From 5f8ad8954554369e262960449b204dc5b626b0f8 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Thu, 9 Jun 2016 19:22:41 +0000 Subject: [PATCH 19/20] Use == instead of is for cygrpc.OperationTypes --- src/python/grpcio/grpc/_channel.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python/grpcio/grpc/_channel.py b/src/python/grpcio/grpc/_channel.py index d9eb5a4b770..7127110b09c 100644 --- a/src/python/grpcio/grpc/_channel.py +++ b/src/python/grpcio/grpc/_channel.py @@ -134,9 +134,9 @@ def _handle_event(event, state, response_deserializer): for batch_operation in event.batch_operations: operation_type = batch_operation.type state.due.remove(operation_type) - if operation_type is cygrpc.OperationType.receive_initial_metadata: + if operation_type == cygrpc.OperationType.receive_initial_metadata: state.initial_metadata = batch_operation.received_metadata - elif operation_type is cygrpc.OperationType.receive_message: + elif operation_type == cygrpc.OperationType.receive_message: serialized_response = batch_operation.received_message.bytes() if serialized_response is not None: response = _common.deserialize( @@ -146,7 +146,7 @@ def _handle_event(event, state, response_deserializer): _abort(state, grpc.StatusCode.INTERNAL, details) else: state.response = response - elif operation_type is cygrpc.OperationType.receive_status_on_client: + elif operation_type == cygrpc.OperationType.receive_status_on_client: state.trailing_metadata = batch_operation.received_metadata if state.code is None: code = _common.CYGRPC_STATUS_CODE_TO_STATUS_CODE.get( From 857495ae449a3c528978047e716341e9e316d64b Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Thu, 9 Jun 2016 14:25:31 -0700 Subject: [PATCH 20/20] fix for #6834 Removed constants kPackageName and kServiceName so multiple services can be defined in one proto. --- src/compiler/objective_c_generator.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index 71a674174d7..6e14d2446f9 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -220,18 +220,13 @@ void PrintMethodImplementations(Printer *printer, {"service_class", ServiceClassName(service)}, {"package", service->file()->package()}}; - printer.Print(vars, - "static NSString *const kPackageName = @\"$package$\";\n"); - printer.Print( - vars, "static NSString *const kServiceName = @\"$service_name$\";\n\n"); - printer.Print(vars, "@implementation $service_class$\n\n"); printer.Print("// Designated initializer\n"); printer.Print("- (instancetype)initWithHost:(NSString *)host {\n"); - printer.Print( + printer.Print(vars, " return (self = [super initWithHost:host" - " packageName:kPackageName serviceName:kServiceName]);\n"); + " packageName:@\"$package$\" serviceName:@\"$service_name$\"]);\n"); printer.Print("}\n\n"); printer.Print( "// Override superclass initializer to disallow different"