Update XDS interop tests for PHP and Ruby

pull/23874/head
Stanley Cheung 5 years ago
parent 7d7e456762
commit a095e3ee7a
  1. 2
      src/php/tests/interop/GPBMetadata/Src/Proto/Grpc/Testing/Messages.php
  2. 2
      src/php/tests/interop/GPBMetadata/Src/Proto/Grpc/Testing/Test.php
  3. 27
      src/php/tests/interop/Grpc/Testing/LoadBalancerStatsResponse.php
  4. 68
      src/php/tests/interop/Grpc/Testing/LoadBalancerStatsResponse/RpcsByPeer.php
  5. 16
      src/php/tests/interop/Grpc/Testing/LoadBalancerStatsResponse_RpcsByPeer.php
  6. 66
      src/php/tests/interop/Grpc/Testing/XdsUpdateHealthServiceClient.php
  7. 159
      src/php/tests/interop/xds_client.php
  8. 118
      src/ruby/pb/test/xds_client.rb
  9. 6
      tools/internal_ci/linux/grpc_xds_php_test_in_docker.sh
  10. 6
      tools/internal_ci/linux/grpc_xds_ruby_test_in_docker.sh

@ -15,7 +15,7 @@ class Messages
return;
}
$pool->internalAddGeneratedFile(hex2bin(
"0ad70e0a257372632f70726f746f2f677270632f74657374696e672f6d657373616765732e70726f746f120c677270632e74657374696e67221a0a09426f6f6c56616c7565120d0a0576616c756518012001280822400a075061796c6f616412270a047479706518012001280e32192e677270632e74657374696e672e5061796c6f616454797065120c0a04626f647918022001280c222b0a0a4563686f537461747573120c0a04636f6465180120012805120f0a076d6573736167651802200128092286030a0d53696d706c655265717565737412300a0d726573706f6e73655f7479706518012001280e32192e677270632e74657374696e672e5061796c6f61645479706512150a0d726573706f6e73655f73697a6518022001280512260a077061796c6f616418032001280b32152e677270632e74657374696e672e5061796c6f616412150a0d66696c6c5f757365726e616d6518042001280812180a1066696c6c5f6f617574685f73636f706518052001280812340a13726573706f6e73655f636f6d7072657373656418062001280b32172e677270632e74657374696e672e426f6f6c56616c756512310a0f726573706f6e73655f73746174757318072001280b32182e677270632e74657374696e672e4563686f53746174757312320a116578706563745f636f6d7072657373656418082001280b32172e677270632e74657374696e672e426f6f6c56616c756512160a0e66696c6c5f7365727665725f6964180920012808121e0a1666696c6c5f677270636c625f726f7574655f74797065180a2001280822be010a0e53696d706c65526573706f6e736512260a077061796c6f616418012001280b32152e677270632e74657374696e672e5061796c6f616412100a08757365726e616d6518022001280912130a0b6f617574685f73636f706518032001280912110a097365727665725f696418042001280912380a11677270636c625f726f7574655f7479706518052001280e321d2e677270632e74657374696e672e477270636c62526f7574655479706512100a08686f73746e616d6518062001280922770a1953747265616d696e67496e70757443616c6c5265717565737412260a077061796c6f616418012001280b32152e677270632e74657374696e672e5061796c6f616412320a116578706563745f636f6d7072657373656418022001280b32172e677270632e74657374696e672e426f6f6c56616c7565223d0a1a53747265616d696e67496e70757443616c6c526573706f6e7365121f0a17616767726567617465645f7061796c6f61645f73697a6518012001280522640a12526573706f6e7365506172616d6574657273120c0a0473697a6518012001280512130a0b696e74657276616c5f7573180220012805122b0a0a636f6d7072657373656418032001280b32172e677270632e74657374696e672e426f6f6c56616c756522e8010a1a53747265616d696e674f757470757443616c6c5265717565737412300a0d726573706f6e73655f7479706518012001280e32192e677270632e74657374696e672e5061796c6f616454797065123d0a13726573706f6e73655f706172616d657465727318022003280b32202e677270632e74657374696e672e526573706f6e7365506172616d657465727312260a077061796c6f616418032001280b32152e677270632e74657374696e672e5061796c6f616412310a0f726573706f6e73655f73746174757318072001280b32182e677270632e74657374696e672e4563686f53746174757322450a1b53747265616d696e674f757470757443616c6c526573706f6e736512260a077061796c6f616418012001280b32152e677270632e74657374696e672e5061796c6f616422330a0f5265636f6e6e656374506172616d7312200a186d61785f7265636f6e6e6563745f6261636b6f66665f6d7318012001280522330a0d5265636f6e6e656374496e666f120e0a0670617373656418012001280812120a0a6261636b6f66665f6d7318022003280522410a184c6f616442616c616e63657253746174735265717565737412100a086e756d5f7270637318012001280512130a0b74696d656f75745f73656318022001280522b3010a194c6f616442616c616e6365725374617473526573706f6e7365124d0a0c727063735f62795f7065657218012003280b32372e677270632e74657374696e672e4c6f616442616c616e6365725374617473526573706f6e73652e52706373427950656572456e74727912140a0c6e756d5f6661696c757265731802200128051a310a0f52706373427950656572456e747279120b0a036b6579180120012809120d0a0576616c75651802200128053a0238012a1f0a0b5061796c6f61645479706512100a0c434f4d505245535341424c4510002a6f0a0f477270636c62526f75746554797065121d0a19475250434c425f524f5554455f545950455f554e4b4e4f574e1000121e0a1a475250434c425f524f5554455f545950455f46414c4c4241434b1001121d0a19475250434c425f524f5554455f545950455f4241434b454e441002620670726f746f33"
"0aaf110a257372632f70726f746f2f677270632f74657374696e672f6d657373616765732e70726f746f120c677270632e74657374696e67221a0a09426f6f6c56616c7565120d0a0576616c756518012001280822400a075061796c6f616412270a047479706518012001280e32192e677270632e74657374696e672e5061796c6f616454797065120c0a04626f647918022001280c222b0a0a4563686f537461747573120c0a04636f6465180120012805120f0a076d6573736167651802200128092286030a0d53696d706c655265717565737412300a0d726573706f6e73655f7479706518012001280e32192e677270632e74657374696e672e5061796c6f61645479706512150a0d726573706f6e73655f73697a6518022001280512260a077061796c6f616418032001280b32152e677270632e74657374696e672e5061796c6f616412150a0d66696c6c5f757365726e616d6518042001280812180a1066696c6c5f6f617574685f73636f706518052001280812340a13726573706f6e73655f636f6d7072657373656418062001280b32172e677270632e74657374696e672e426f6f6c56616c756512310a0f726573706f6e73655f73746174757318072001280b32182e677270632e74657374696e672e4563686f53746174757312320a116578706563745f636f6d7072657373656418082001280b32172e677270632e74657374696e672e426f6f6c56616c756512160a0e66696c6c5f7365727665725f6964180920012808121e0a1666696c6c5f677270636c625f726f7574655f74797065180a2001280822be010a0e53696d706c65526573706f6e736512260a077061796c6f616418012001280b32152e677270632e74657374696e672e5061796c6f616412100a08757365726e616d6518022001280912130a0b6f617574685f73636f706518032001280912110a097365727665725f696418042001280912380a11677270636c625f726f7574655f7479706518052001280e321d2e677270632e74657374696e672e477270636c62526f7574655479706512100a08686f73746e616d6518062001280922770a1953747265616d696e67496e70757443616c6c5265717565737412260a077061796c6f616418012001280b32152e677270632e74657374696e672e5061796c6f616412320a116578706563745f636f6d7072657373656418022001280b32172e677270632e74657374696e672e426f6f6c56616c7565223d0a1a53747265616d696e67496e70757443616c6c526573706f6e7365121f0a17616767726567617465645f7061796c6f61645f73697a6518012001280522640a12526573706f6e7365506172616d6574657273120c0a0473697a6518012001280512130a0b696e74657276616c5f7573180220012805122b0a0a636f6d7072657373656418032001280b32172e677270632e74657374696e672e426f6f6c56616c756522e8010a1a53747265616d696e674f757470757443616c6c5265717565737412300a0d726573706f6e73655f7479706518012001280e32192e677270632e74657374696e672e5061796c6f616454797065123d0a13726573706f6e73655f706172616d657465727318022003280b32202e677270632e74657374696e672e526573706f6e7365506172616d657465727312260a077061796c6f616418032001280b32152e677270632e74657374696e672e5061796c6f616412310a0f726573706f6e73655f73746174757318072001280b32182e677270632e74657374696e672e4563686f53746174757322450a1b53747265616d696e674f757470757443616c6c526573706f6e736512260a077061796c6f616418012001280b32152e677270632e74657374696e672e5061796c6f616422330a0f5265636f6e6e656374506172616d7312200a186d61785f7265636f6e6e6563745f6261636b6f66665f6d7318012001280522330a0d5265636f6e6e656374496e666f120e0a0670617373656418012001280812120a0a6261636b6f66665f6d7318022003280522410a184c6f616442616c616e63657253746174735265717565737412100a086e756d5f7270637318012001280512130a0b74696d656f75745f736563180220012805228b040a194c6f616442616c616e6365725374617473526573706f6e7365124d0a0c727063735f62795f7065657218012003280b32372e677270632e74657374696e672e4c6f616442616c616e6365725374617473526573706f6e73652e52706373427950656572456e74727912140a0c6e756d5f6661696c7572657318022001280512510a0e727063735f62795f6d6574686f6418032003280b32392e677270632e74657374696e672e4c6f616442616c616e6365725374617473526573706f6e73652e5270637342794d6574686f64456e7472791a99010a0a5270637342795065657212580a0c727063735f62795f7065657218012003280b32422e677270632e74657374696e672e4c6f616442616c616e6365725374617473526573706f6e73652e527063734279506565722e52706373427950656572456e7472791a310a0f52706373427950656572456e747279120b0a036b6579180120012809120d0a0576616c75651802200128053a0238011a310a0f52706373427950656572456e747279120b0a036b6579180120012809120d0a0576616c75651802200128053a0238011a670a115270637342794d6574686f64456e747279120b0a036b657918012001280912410a0576616c756518022001280b32322e677270632e74657374696e672e4c6f616442616c616e6365725374617473526573706f6e73652e527063734279506565723a0238012a1f0a0b5061796c6f61645479706512100a0c434f4d505245535341424c4510002a6f0a0f477270636c62526f75746554797065121d0a19475250434c425f524f5554455f545950455f554e4b4e4f574e1000121e0a1a475250434c425f524f5554455f545950455f46414c4c4241434b1001121d0a19475250434c425f524f5554455f545950455f4241434b454e441002620670726f746f33"
), true);
static::$is_initialized = true;

@ -17,7 +17,7 @@ class Test
\GPBMetadata\Src\Proto\Grpc\Testing\PBEmpty::initOnce();
\GPBMetadata\Src\Proto\Grpc\Testing\Messages::initOnce();
$pool->internalAddGeneratedFile(hex2bin(
"0aca090a217372632f70726f746f2f677270632f74657374696e672f746573742e70726f746f120c677270632e74657374696e671a257372632f70726f746f2f677270632f74657374696e672f6d657373616765732e70726f746f32e7050a0b546573745365727669636512430a09456d70747943616c6c121a2e677270632e74657374696e672e456d7074794d6573736167651a1a2e677270632e74657374696e672e456d7074794d65737361676512460a09556e61727943616c6c121b2e677270632e74657374696e672e53696d706c65526571756573741a1c2e677270632e74657374696e672e53696d706c65526573706f6e7365124f0a12436163686561626c65556e61727943616c6c121b2e677270632e74657374696e672e53696d706c65526571756573741a1c2e677270632e74657374696e672e53696d706c65526573706f6e7365126c0a1353747265616d696e674f757470757443616c6c12282e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526571756573741a292e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526573706f6e7365300112690a1253747265616d696e67496e70757443616c6c12272e677270632e74657374696e672e53747265616d696e67496e70757443616c6c526571756573741a282e677270632e74657374696e672e53747265616d696e67496e70757443616c6c526573706f6e7365280112690a0e46756c6c4475706c657843616c6c12282e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526571756573741a292e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526573706f6e73652801300112690a0e48616c664475706c657843616c6c12282e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526571756573741a292e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526573706f6e736528013001124b0a11556e696d706c656d656e74656443616c6c121a2e677270632e74657374696e672e456d7074794d6573736167651a1a2e677270632e74657374696e672e456d7074794d65737361676532630a14556e696d706c656d656e74656453657276696365124b0a11556e696d706c656d656e74656443616c6c121a2e677270632e74657374696e672e456d7074794d6573736167651a1a2e677270632e74657374696e672e456d7074794d6573736167653297010a105265636f6e6e6563745365727669636512420a055374617274121d2e677270632e74657374696e672e5265636f6e6e656374506172616d731a1a2e677270632e74657374696e672e456d7074794d657373616765123f0a0453746f70121a2e677270632e74657374696e672e456d7074794d6573736167651a1b2e677270632e74657374696e672e5265636f6e6e656374496e666f327f0a184c6f616442616c616e63657253746174735365727669636512630a0e476574436c69656e74537461747312262e677270632e74657374696e672e4c6f616442616c616e6365725374617473526571756573741a272e677270632e74657374696e672e4c6f616442616c616e6365725374617473526573706f6e73652200620670726f746f33"
"0af40a0a217372632f70726f746f2f677270632f74657374696e672f746573742e70726f746f120c677270632e74657374696e671a257372632f70726f746f2f677270632f74657374696e672f6d657373616765732e70726f746f32e7050a0b546573745365727669636512430a09456d70747943616c6c121a2e677270632e74657374696e672e456d7074794d6573736167651a1a2e677270632e74657374696e672e456d7074794d65737361676512460a09556e61727943616c6c121b2e677270632e74657374696e672e53696d706c65526571756573741a1c2e677270632e74657374696e672e53696d706c65526573706f6e7365124f0a12436163686561626c65556e61727943616c6c121b2e677270632e74657374696e672e53696d706c65526571756573741a1c2e677270632e74657374696e672e53696d706c65526573706f6e7365126c0a1353747265616d696e674f757470757443616c6c12282e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526571756573741a292e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526573706f6e7365300112690a1253747265616d696e67496e70757443616c6c12272e677270632e74657374696e672e53747265616d696e67496e70757443616c6c526571756573741a282e677270632e74657374696e672e53747265616d696e67496e70757443616c6c526573706f6e7365280112690a0e46756c6c4475706c657843616c6c12282e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526571756573741a292e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526573706f6e73652801300112690a0e48616c664475706c657843616c6c12282e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526571756573741a292e677270632e74657374696e672e53747265616d696e674f757470757443616c6c526573706f6e736528013001124b0a11556e696d706c656d656e74656443616c6c121a2e677270632e74657374696e672e456d7074794d6573736167651a1a2e677270632e74657374696e672e456d7074794d65737361676532630a14556e696d706c656d656e74656453657276696365124b0a11556e696d706c656d656e74656443616c6c121a2e677270632e74657374696e672e456d7074794d6573736167651a1a2e677270632e74657374696e672e456d7074794d6573736167653297010a105265636f6e6e6563745365727669636512420a055374617274121d2e677270632e74657374696e672e5265636f6e6e656374506172616d731a1a2e677270632e74657374696e672e456d7074794d657373616765123f0a0453746f70121a2e677270632e74657374696e672e456d7074794d6573736167651a1b2e677270632e74657374696e672e5265636f6e6e656374496e666f327f0a184c6f616442616c616e63657253746174735365727669636512630a0e476574436c69656e74537461747312262e677270632e74657374696e672e4c6f616442616c616e6365725374617473526571756573741a272e677270632e74657374696e672e4c6f616442616c616e6365725374617473526573706f6e7365220032a7010a165864735570646174654865616c74685365727669636512440a0a53657453657276696e67121a2e677270632e74657374696e672e456d7074794d6573736167651a1a2e677270632e74657374696e672e456d7074794d65737361676512470a0d5365744e6f7453657276696e67121a2e677270632e74657374696e672e456d7074794d6573736167651a1a2e677270632e74657374696e672e456d7074794d657373616765620670726f746f33"
), true);
static::$is_initialized = true;

@ -25,6 +25,10 @@ class LoadBalancerStatsResponse extends \Google\Protobuf\Internal\Message
* Generated from protobuf field <code>int32 num_failures = 2;</code>
*/
protected $num_failures = 0;
/**
* Generated from protobuf field <code>map<string, .grpc.testing.LoadBalancerStatsResponse.RpcsByPeer> rpcs_by_method = 3;</code>
*/
private $rpcs_by_method;
/**
* Constructor.
@ -36,6 +40,7 @@ class LoadBalancerStatsResponse extends \Google\Protobuf\Internal\Message
* The number of completed RPCs for each peer.
* @type int $num_failures
* The number of RPCs that failed to record a remote peer.
* @type array|\Google\Protobuf\Internal\MapField $rpcs_by_method
* }
*/
public function __construct($data = NULL) {
@ -95,5 +100,27 @@ class LoadBalancerStatsResponse extends \Google\Protobuf\Internal\Message
return $this;
}
/**
* Generated from protobuf field <code>map<string, .grpc.testing.LoadBalancerStatsResponse.RpcsByPeer> rpcs_by_method = 3;</code>
* @return \Google\Protobuf\Internal\MapField
*/
public function getRpcsByMethod()
{
return $this->rpcs_by_method;
}
/**
* Generated from protobuf field <code>map<string, .grpc.testing.LoadBalancerStatsResponse.RpcsByPeer> rpcs_by_method = 3;</code>
* @param array|\Google\Protobuf\Internal\MapField $var
* @return $this
*/
public function setRpcsByMethod($var)
{
$arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::MESSAGE, \Grpc\Testing\LoadBalancerStatsResponse\RpcsByPeer::class);
$this->rpcs_by_method = $arr;
return $this;
}
}

@ -0,0 +1,68 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: src/proto/grpc/testing/messages.proto
namespace Grpc\Testing\LoadBalancerStatsResponse;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>grpc.testing.LoadBalancerStatsResponse.RpcsByPeer</code>
*/
class RpcsByPeer extends \Google\Protobuf\Internal\Message
{
/**
* The number of completed RPCs for each peer.
*
* Generated from protobuf field <code>map<string, int32> rpcs_by_peer = 1;</code>
*/
private $rpcs_by_peer;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type array|\Google\Protobuf\Internal\MapField $rpcs_by_peer
* The number of completed RPCs for each peer.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Src\Proto\Grpc\Testing\Messages::initOnce();
parent::__construct($data);
}
/**
* The number of completed RPCs for each peer.
*
* Generated from protobuf field <code>map<string, int32> rpcs_by_peer = 1;</code>
* @return \Google\Protobuf\Internal\MapField
*/
public function getRpcsByPeer()
{
return $this->rpcs_by_peer;
}
/**
* The number of completed RPCs for each peer.
*
* Generated from protobuf field <code>map<string, int32> rpcs_by_peer = 1;</code>
* @param array|\Google\Protobuf\Internal\MapField $var
* @return $this
*/
public function setRpcsByPeer($var)
{
$arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::INT32);
$this->rpcs_by_peer = $arr;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(RpcsByPeer::class, \Grpc\Testing\LoadBalancerStatsResponse_RpcsByPeer::class);

@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: src/proto/grpc/testing/messages.proto
namespace Grpc\Testing;
if (false) {
/**
* This class is deprecated. Use Grpc\Testing\LoadBalancerStatsResponse\RpcsByPeer instead.
* @deprecated
*/
class LoadBalancerStatsResponse_RpcsByPeer {}
}
class_exists(LoadBalancerStatsResponse\RpcsByPeer::class);
@trigger_error('Grpc\Testing\LoadBalancerStatsResponse_RpcsByPeer is deprecated and will be removed in the next major release. Use Grpc\Testing\LoadBalancerStatsResponse\RpcsByPeer instead', E_USER_DEPRECATED);

@ -0,0 +1,66 @@
<?php
// GENERATED CODE -- DO NOT EDIT!
// Original file comments:
// Copyright 2015-2016 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// An integration test service that covers all the method signature permutations
// of unary/streaming requests/responses.
//
namespace Grpc\Testing;
/**
* A service to remotely control health status of an xDS test server.
*/
class XdsUpdateHealthServiceClient extends \Grpc\BaseStub {
/**
* @param string $hostname hostname
* @param array $opts channel options
* @param \Grpc\Channel $channel (optional) re-use channel object
*/
public function __construct($hostname, $opts, $channel = null) {
parent::__construct($hostname, $opts, $channel);
}
/**
* @param \Grpc\Testing\EmptyMessage $argument input argument
* @param array $metadata metadata
* @param array $options call options
* @return \Grpc\Testing\EmptyMessage
*/
public function SetServing(\Grpc\Testing\EmptyMessage $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/grpc.testing.XdsUpdateHealthService/SetServing',
$argument,
['\Grpc\Testing\EmptyMessage', 'decode'],
$metadata, $options);
}
/**
* @param \Grpc\Testing\EmptyMessage $argument input argument
* @param array $metadata metadata
* @param array $options call options
* @return \Grpc\Testing\EmptyMessage
*/
public function SetNotServing(\Grpc\Testing\EmptyMessage $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/grpc.testing.XdsUpdateHealthService/SetNotServing',
$argument,
['\Grpc\Testing\EmptyMessage', 'decode'],
$metadata, $options);
}
}

@ -33,13 +33,14 @@ class LoadBalancerStatsService
function getClientStats(\Grpc\Testing\LoadBalancerStatsRequest $request) {
$num_rpcs = $request->getNumRpcs();
$timeout_sec = $request->getTimeoutSec();
$rpcs_by_method = [];
$rpcs_by_peer = [];
$num_failures = $num_rpcs;
$num_failures = 0;
// Heavy limitation now: the server is blocking, until all
// the necessary num_rpcs are finished, or timeout is reached
global $client_thread;
$start_id = count($client_thread->results) + 1;
$start_id = $client_thread->num_results + 1;
$end_id = $start_id + $num_rpcs;
$now = hrtime(true);
$timeout = $now[0] + ($now[1] / 1e9) + $timeout_sec;
@ -50,7 +51,7 @@ class LoadBalancerStatsService
break;
}
// Thread variable seems to be read-only
$curr_id = count($client_thread->results);
$curr_id = $client_thread->num_results;
if ($curr_id >= $end_id) {
break;
}
@ -58,19 +59,52 @@ class LoadBalancerStatsService
}
// Tally up results
$end_id = min($end_id, count($client_thread->results));
for ($i = $start_id; $i < $end_id; $i++) {
$hostname = $client_thread->results[$i];
if ($hostname) {
$num_failures -= 1;
if (!array_key_exists($hostname, $rpcs_by_peer)) {
$rpcs_by_peer[$hostname] = 0;
$end_id = min($end_id, $client_thread->num_results);
// "$client_thread->results" will be in the form of
// [
// 'rpc1' => [
// 'hostname1', '', 'hostname2', 'hostname1', '', ...
// ],
// 'rpc2' => [
// '', 'hostname1', 'hostname2', '', 'hostname2', ...
// ],
// ]
foreach ($client_thread->results as $rpc => $results) {
// initialize, can always start from scratch here
$rpcs_by_method[$rpc] = [];
for ($i = $start_id; $i < $end_id; $i++) {
$hostname = $results[$i];
if ($hostname) {
// initialize in case we haven't seen this hostname
// before
if (!array_key_exists($hostname, $rpcs_by_method[$rpc])) {
$rpcs_by_method[$rpc][$hostname] = 0;
}
if (!array_key_exists($hostname, $rpcs_by_peer)) {
$rpcs_by_peer[$hostname] = 0;
}
// increment the remote hostname distribution histogram
// both by overall, and broken down per RPC
$rpcs_by_method[$rpc][$hostname] += 1;
$rpcs_by_peer[$hostname] += 1;
} else {
// $num_failures here are counted per individual RPC
$num_failures += 1;
}
$rpcs_by_peer[$hostname] += 1;
}
}
// Convert our hashmaps above into protobuf objects
$response = new Grpc\Testing\LoadBalancerStatsResponse();
$rpcs_by_method_map = [];
foreach ($rpcs_by_method as $rpc => $rpcs_by_peer_per_method) {
$rpcs_by_peer_proto_obj
= new Grpc\Testing\LoadBalancerStatsResponse\RpcsByPeer();
$rpcs_by_peer_proto_obj->setRpcsByPeer($rpcs_by_peer_per_method);
$rpcs_by_method_map[$rpc] = $rpcs_by_peer_proto_obj;
}
$response->setRpcsByPeer($rpcs_by_peer);
$response->setRpcsByMethod($rpcs_by_method_map);
$response->setNumFailures($num_failures);
return $response;
}
@ -83,28 +117,74 @@ class ClientThread extends Thread {
private $target_seconds_between_rpcs_;
private $fail_on_failed_rpcs_;
private $autoload_path_;
private $TIMEOUT_US = 30 * 1e6; // 30 seconds
public $num_results = 0;
public $results;
public function __construct($server_address, $qps, $fail_on_failed_rpcs,
$rpcs_to_send, $metadata_to_send,
$autoload_path) {
$this->server_address_ = $server_address;
$this->target_seconds_between_rpcs_ = 1.0 / $qps;
$this->fail_on_failed_rpcs_ = $fail_on_failed_rpcs;
$this->rpcs_to_send = explode(',', $rpcs_to_send);
// Convert input in the form of
// rpc1:k1:v1,rpc2:k2:v2,rpc1:k3:v3
// into
// [
// 'rpc1' => [
// 'k1' => 'v1',
// 'k3' => 'v3',
// ],
// 'rpc2' => [
// 'k2' => 'v2'
// ],
// ]
$this->metadata_to_send = [];
if ($_all_metadata = explode(',', $metadata_to_send)) {
foreach ($_all_metadata as $one_metadata_pair) {
list($rpc,
$metadata_key,
$metadata_value) = explode(':', $one_metadata_pair);
// initialize in case we haven't seen this rpc before
if (!array_key_exists($rpc, $this->metadata_to_send)) {
$this->metadata_to_send[$rpc] = [];
}
$this->metadata_to_send[$rpc][$metadata_key]
= $metadata_value;
}
}
$this->autoload_path_ = $autoload_path;
$this->simple_request = new Grpc\Testing\SimpleRequest();
$this->empty_request = new Grpc\Testing\EmptyMessage();
$this->results = [];
foreach ($this->rpcs_to_send as $rpc) {
$this->results[$rpc] = [];
}
}
public function sendUnaryCall($stub, $metadata) {
return $stub->UnaryCall($this->simple_request,
$metadata,
['timeout' => $this->TIMEOUT_US]);
}
public function sendEmptyCall($stub, $metadata) {
return $stub->EmptyCall($this->empty_request,
$metadata,
['timeout' => $this->TIMEOUT_US]);
}
public function run() {
// Autoloaded classes do not get inherited in threads.
// Hence we need to do this.
require_once($this->autoload_path_);
$TIMEOUT_US = 30 * 1e6; // 30 seconds
$stub = new Grpc\Testing\TestServiceClient($this->server_address_, [
'credentials' => Grpc\ChannelCredentials::createInsecure()
]);
$request = new Grpc\Testing\SimpleRequest();
$target_next_start_us = hrtime(true) / 1000; # hrtime returns nanoseconds
# hrtime returns nanoseconds
$target_next_start_us = hrtime(true) / 1000;
while (true) {
$now_us = hrtime(true) / 1000;
$sleep_us = $target_next_start_us - $now_us;
@ -121,18 +201,43 @@ class ClientThread extends Thread {
($this->target_seconds_between_rpcs_ * 1e6);
usleep($sleep_us);
}
list($response, $status)
= $stub->UnaryCall($request, [],
['timeout' => $TIMEOUT_US])->wait();
if ($status->code == Grpc\STATUS_OK) {
$this->results[] = $response->getHostname();
} else {
if ($this->fail_on_failed_rpcs_) {
throw new Exception('UnaryCall failed with status '
. $status->code);
foreach ($this->rpcs_to_send as $rpc) {
$metadata = array_key_exists(
$rpc, $this->metadata_to_send) ?
$this->metadata_to_send[$rpc] : [];
// This copy is somehow necessary because
// $this->metadata_to_send[$rpc] somehow becomes a
// Volatile object, instead of an associative array.
$metadata_array = [];
foreach ($metadata as $key => $value) {
$metadata_array[$key] = [$value];
}
$call = null;
if ($rpc == 'UnaryCall') {
$call = $this->sendUnaryCall($stub, $metadata_array);
} else if ($rpc == 'EmptyCall') {
$call = $this->sendEmptyCall($stub, $metadata_array);
} else {
throw new Exception("Unhandled rpc $rpc");
}
// the remote peer is being returned as part of the
// initial metadata, according to the test spec
$initial_metadata = $call->getMetadata();
list($response, $status) = $call->wait();
if ($status->code == Grpc\STATUS_OK &&
array_key_exists('hostname', $initial_metadata)) {
$this->results[$rpc][] = $initial_metadata['hostname'][0];
} else {
if ($this->fail_on_failed_rpcs_) {
throw new Exception("$rpc failed with status "
. $status->code);
}
$this->results[$rpc][] = "";
}
$this->results[] = "";
}
// $num_results here is only incremented when the group of
// all $rpcs_to_send are done.
$this->num_results++;
}
}
@ -145,10 +250,14 @@ class ClientThread extends Thread {
// Note: num_channels are currently ignored for now
$args = getopt('', ['fail_on_failed_rpcs:', 'num_channels:',
'rpc:', 'metadata:',
'server:', 'stats_port:', 'qps:']);
$client_thread = new ClientThread($args['server'], $args['qps'],
$args['fail_on_failed_rpcs'],
(empty($args['rpc']) ? 'UnaryCall'
: $args['rpc']),
$args['metadata'],
$autoload_path);
$client_thread->start();

@ -81,6 +81,7 @@ class TestTarget < Grpc::Testing::LoadBalancerStatsService::Service
watcher = {}
$watchers_mutex.synchronize do
watcher = {
"rpcs_by_method" => Hash.new(),
"rpcs_by_peer" => Hash.new(0),
"rpcs_needed" => req['num_rpcs'],
"no_remote_peer" => 0
@ -95,17 +96,45 @@ class TestTarget < Grpc::Testing::LoadBalancerStatsService::Service
end
$watchers.delete_at($watchers.index(watcher))
end
# convert results into proper proto object
rpcs_by_method = {}
watcher['rpcs_by_method'].each do | rpc_name, rpcs_by_peer |
rpcs_by_method[rpc_name] = LoadBalancerStatsResponse::RpcsByPeer.new(
rpcs_by_peer: rpcs_by_peer
)
end
LoadBalancerStatsResponse.new(
rpcs_by_method: rpcs_by_method,
rpcs_by_peer: watcher['rpcs_by_peer'],
num_failures: watcher['no_remote_peer'] + watcher['rpcs_needed']
);
end
end
# execute 1 RPC and return remote hostname
def execute_rpc(op, fail_on_failed_rpcs)
remote_peer = ""
begin
op.execute
if op.metadata.key?('hostname')
remote_peer = op.metadata['hostname']
end
rescue GRPC::BadStatus => e
GRPC.logger.info("ruby xds: rpc failed:|#{e.message}|, " \
"this may or may not be expected")
if fail_on_failed_rpcs
raise e
end
end
remote_peer
end
# send 1 rpc every 1/qps second
def run_test_loop(stub, target_seconds_between_rpcs, fail_on_failed_rpcs)
def run_test_loop(stub, target_seconds_between_rpcs, fail_on_failed_rpcs,
rpcs_to_send, metadata_to_send)
include Grpc::Testing
req = SimpleRequest.new()
simple_req = SimpleRequest.new()
empty_req = Empty.new()
target_next_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
while !$shutdown
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@ -121,25 +150,42 @@ def run_test_loop(stub, target_seconds_between_rpcs, fail_on_failed_rpcs)
target_next_start += target_seconds_between_rpcs
sleep(sleep_seconds)
end
begin
deadline = GRPC::Core::TimeConsts::from_relative_time(30) # 30 seconds
resp = stub.unary_call(req, deadline: deadline)
remote_peer = resp.hostname
rescue GRPC::BadStatus => e
remote_peer = ""
GRPC.logger.info("ruby xds: rpc failed:|#{e.message}|, " \
"this may or may not be expected")
if fail_on_failed_rpcs
raise e
deadline = GRPC::Core::TimeConsts::from_relative_time(30) # 30 seconds
results = {}
rpcs_to_send.each do |rpc|
metadata = metadata_to_send.key?(rpc) ? metadata_to_send[rpc] : {}
if rpc == 'UnaryCall'
op = stub.unary_call(simple_req,
metadata: metadata,
deadline: deadline,
return_op: true)
elsif rpc == 'EmptyCall'
op = stub.empty_call(empty_req,
metadata: metadata,
deadline: deadline,
return_op: true)
else
raise "Unsupported rpc %s" % [rpc]
end
results[rpc] = execute_rpc(op, fail_on_failed_rpcs)
end
$watchers_mutex.synchronize do
$watchers.each do |watcher|
# this is counted once when each group of all rpcs_to_send were done
watcher['rpcs_needed'] -= 1
if remote_peer.strip.empty?
watcher['no_remote_peer'] += 1
else
watcher['rpcs_by_peer'][remote_peer] += 1
results.each do | rpc_name, remote_peer |
if remote_peer.strip.empty?
# error is counted per individual RPC
watcher['no_remote_peer'] += 1
else
if not watcher['rpcs_by_method'].key?(rpc_name)
watcher['rpcs_by_method'][rpc_name] = Hash.new(0)
end
# increment the remote hostname distribution histogram
# both by overall, and broken down per RPC
watcher['rpcs_by_method'][rpc_name][remote_peer] += 1
watcher['rpcs_by_peer'][remote_peer] += 1
end
end
end
$watchers_cv.broadcast
@ -149,6 +195,7 @@ end
# Args is used to hold the command line info.
Args = Struct.new(:fail_on_failed_rpcs, :num_channels,
:rpc, :metadata,
:server, :stats_port, :qps)
# validates the command line options, returning them as a Hash.
@ -156,6 +203,8 @@ def parse_args
args = Args.new
args['fail_on_failed_rpcs'] = false
args['num_channels'] = 1
args['rpc'] = 'UnaryCall'
args['metadata'] = ''
OptionParser.new do |opts|
opts.on('--fail_on_failed_rpcs BOOL', ['false', 'true']) do |v|
args['fail_on_failed_rpcs'] = v == 'true'
@ -163,6 +212,12 @@ def parse_args
opts.on('--num_channels CHANNELS', 'number of channels') do |v|
args['num_channels'] = v.to_i
end
opts.on('--rpc RPCS_TO_SEND', 'list of RPCs to send') do |v|
args['rpc'] = v
end
opts.on('--metadata METADATA_TO_SEND', 'metadata to send per RPC') do |v|
args['metadata'] = v
end
opts.on('--server SERVER_HOST', 'server hostname') do |v|
GRPC.logger.info("ruby xds: server address is #{v}")
args['server'] = v
@ -195,11 +250,40 @@ def main
# The client just sends unary rpcs continuously in a regular interval
stub = create_stub(opts)
target_seconds_between_rpcs = (1.0 / opts['qps'].to_f)
rpcs_to_send = []
if opts['rpc']
rpcs_to_send = opts['rpc'].split(',')
end
# Convert 'metadata' input in the form of
# rpc1:k1:v1,rpc2:k2:v2,rpc1:k3:v3
# into
# {
# 'rpc1' => {
# 'k1' => 'v1',
# 'k3' => 'v3',
# },
# 'rpc2' => {
# 'k2' => 'v2'
# },
# }
metadata_to_send = {}
if opts['metadata']
metadata_entries = opts['metadata'].split(',')
metadata_entries.each do |e|
(rpc_name, metadata_key, metadata_value) = e.split(':')
# initialize if we haven't seen this rpc_name yet
if !metadata_to_send.key?(rpc_name)
metadata_to_send[rpc_name] = {}
end
metadata_to_send[rpc_name][metadata_key] = metadata_value
end
end
client_threads = Array.new
opts['num_channels'].times {
client_threads << Thread.new {
run_test_loop(stub, target_seconds_between_rpcs,
opts['fail_on_failed_rpcs'])
opts['fail_on_failed_rpcs'],
rpcs_to_send, metadata_to_send)
}
}

@ -60,10 +60,10 @@ export CC=/usr/bin/gcc
GRPC_VERBOSITY=debug GRPC_TRACE=xds_client,xds_resolver,xds_routing_lb,cds_lb,eds_lb,priority_lb,weighted_target_lb,lrs_lb "$PYTHON" \
tools/run_tests/run_xds_tests.py \
--test_case=all \
--test_case="all,path_matching,header_matching" \
--project_id=grpc-testing \
--source_image=projects/grpc-testing/global/images/xds-test-server \
--source_image=projects/grpc-testing/global/images/xds-test-server-2 \
--path_to_server_binary=/java_server/grpc-java/interop-testing/build/install/grpc-interop-testing/bin/xds-test-server \
--gcp_suffix=$(date '+%s') \
--verbose \
--client_cmd='php -d extension=grpc.so -d extension=pthreads.so src/php/tests/interop/xds_client.php --server=xds:///{server_uri} --stats_port={stats_port} --qps={qps}'
--client_cmd='php -d extension=grpc.so -d extension=pthreads.so src/php/tests/interop/xds_client.php --server=xds:///{server_uri} --stats_port={stats_port} --qps={qps} {fail_on_failed_rpc} {rpcs_to_send} {metadata_to_send}'

@ -50,10 +50,10 @@ touch "$TOOLS_DIR"/src/proto/grpc/testing/__init__.py
GRPC_VERBOSITY=debug GRPC_TRACE=xds_client,xds_resolver,xds_routing_lb,cds_lb,eds_lb,priority_lb,weighted_target_lb,lrs_lb "$PYTHON" \
tools/run_tests/run_xds_tests.py \
--test_case=all \
--test_case="all,path_matching,header_matching" \
--project_id=grpc-testing \
--source_image=projects/grpc-testing/global/images/xds-test-server \
--source_image=projects/grpc-testing/global/images/xds-test-server-2 \
--path_to_server_binary=/java_server/grpc-java/interop-testing/build/install/grpc-interop-testing/bin/xds-test-server \
--gcp_suffix=$(date '+%s') \
--verbose \
--client_cmd='ruby src/ruby/pb/test/xds_client.rb --server=xds:///{server_uri} --stats_port={stats_port} --qps={qps}'
--client_cmd='ruby src/ruby/pb/test/xds_client.rb --server=xds:///{server_uri} --stats_port={stats_port} --qps={qps} {fail_on_failed_rpc} {rpcs_to_send} {metadata_to_send}'

Loading…
Cancel
Save