From 4677c70684c182e99c67bff7b195cd2dadfa2cf5 Mon Sep 17 00:00:00 2001 From: ZhouyihaiDing Date: Thu, 31 May 2018 16:02:46 -0700 Subject: [PATCH] PHP: fix flaky tests --- .../tests/unit_tests/CallCredentials2Test.php | 1 + .../tests/unit_tests/CallCredentialsTest.php | 1 + src/php/tests/unit_tests/CallTest.php | 6 ++-- src/php/tests/unit_tests/EndToEndTest.php | 5 +++- src/php/tests/unit_tests/InterceptorTest.php | 30 +++++++++++++++---- .../tests/unit_tests/SecureEndToEndTest.php | 2 ++ src/php/tests/unit_tests/ServerTest.php | 5 +++- 7 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/php/tests/unit_tests/CallCredentials2Test.php b/src/php/tests/unit_tests/CallCredentials2Test.php index 1c7e0c0ff6f..c63029f121b 100644 --- a/src/php/tests/unit_tests/CallCredentials2Test.php +++ b/src/php/tests/unit_tests/CallCredentials2Test.php @@ -35,6 +35,7 @@ class CallCredentials2Test extends PHPUnit_Framework_TestCase $this->channel = new Grpc\Channel( 'localhost:'.$this->port, [ + 'force_new' => true, 'grpc.ssl_target_name_override' => $this->host_override, 'grpc.default_authority' => $this->host_override, 'credentials' => $credentials, diff --git a/src/php/tests/unit_tests/CallCredentialsTest.php b/src/php/tests/unit_tests/CallCredentialsTest.php index 4b5721d76ac..818b823da71 100644 --- a/src/php/tests/unit_tests/CallCredentialsTest.php +++ b/src/php/tests/unit_tests/CallCredentialsTest.php @@ -41,6 +41,7 @@ class CallCredentialsTest extends PHPUnit_Framework_TestCase $this->channel = new Grpc\Channel( 'localhost:'.$this->port, [ + 'force_new' => true, 'grpc.ssl_target_name_override' => $this->host_override, 'grpc.default_authority' => $this->host_override, 'credentials' => $this->credentials, diff --git a/src/php/tests/unit_tests/CallTest.php b/src/php/tests/unit_tests/CallTest.php index c5e1890a98b..be1d77fe7ad 100644 --- a/src/php/tests/unit_tests/CallTest.php +++ b/src/php/tests/unit_tests/CallTest.php @@ -24,12 +24,14 @@ class CallTest extends PHPUnit_Framework_TestCase public static function setUpBeforeClass() { self::$server = new Grpc\Server([]); - self::$port = self::$server->addHttp2Port('0.0.0.0:0'); + self::$port = self::$server->addHttp2Port('0.0.0.0:53000'); } public function setUp() { - $this->channel = new Grpc\Channel('localhost:'.self::$port, []); + $this->channel = new Grpc\Channel('localhost:'.self::$port, [ + 'force_new' => true, + ]); $this->call = new Grpc\Call($this->channel, '/foo', Grpc\Timeval::infFuture()); diff --git a/src/php/tests/unit_tests/EndToEndTest.php b/src/php/tests/unit_tests/EndToEndTest.php index b54f1d87c9f..d0965655e0a 100644 --- a/src/php/tests/unit_tests/EndToEndTest.php +++ b/src/php/tests/unit_tests/EndToEndTest.php @@ -22,13 +22,16 @@ class EndToEndTest extends PHPUnit_Framework_TestCase { $this->server = new Grpc\Server([]); $this->port = $this->server->addHttp2Port('0.0.0.0:0'); - $this->channel = new Grpc\Channel('localhost:'.$this->port, []); + $this->channel = new Grpc\Channel('localhost:'.$this->port, [ + "force_new" => true, + ]); $this->server->start(); } public function tearDown() { $this->channel->close(); + unset($this->server); } public function testSimpleRequestBody() diff --git a/src/php/tests/unit_tests/InterceptorTest.php b/src/php/tests/unit_tests/InterceptorTest.php index 11c5b4325a9..d18c27c2c7f 100644 --- a/src/php/tests/unit_tests/InterceptorTest.php +++ b/src/php/tests/unit_tests/InterceptorTest.php @@ -206,13 +206,16 @@ class InterceptorTest extends PHPUnit_Framework_TestCase { $this->server = new Grpc\Server([]); $this->port = $this->server->addHttp2Port('0.0.0.0:0'); - $this->channel = new Grpc\Channel('localhost:'.$this->port, ['credentials' => Grpc\ChannelCredentials::createInsecure()]); + $this->channel = new Grpc\Channel('localhost:'.$this->port, [ + 'force_new' => true, + 'credentials' => Grpc\ChannelCredentials::createInsecure()]); $this->server->start(); } public function tearDown() { $this->channel->close(); + unset($this->server); } @@ -222,6 +225,7 @@ class InterceptorTest extends PHPUnit_Framework_TestCase $channel_matadata_interceptor = new ChangeMetadataInterceptor(); $intercept_channel = Grpc\Interceptor::intercept($this->channel, $channel_matadata_interceptor); $client = new InterceptorClient('localhost:'.$this->port, [ + 'force_new' => true, 'credentials' => Grpc\ChannelCredentials::createInsecure(), ], $intercept_channel); $req = new SimpleRequest($req_text); @@ -250,6 +254,7 @@ class InterceptorTest extends PHPUnit_Framework_TestCase $intercept_channel1 = Grpc\Interceptor::intercept($this->channel, $channel_matadata_interceptor); $intercept_channel2 = Grpc\Interceptor::intercept($intercept_channel1, $channel_matadata_intercepto2); $client = new InterceptorClient('localhost:'.$this->port, [ + 'force_new' => true, 'credentials' => Grpc\ChannelCredentials::createInsecure(), ], $intercept_channel2); @@ -275,6 +280,7 @@ class InterceptorTest extends PHPUnit_Framework_TestCase $intercept_channel3 = Grpc\Interceptor::intercept($this->channel, [$channel_matadata_intercepto2, $channel_matadata_interceptor]); $client = new InterceptorClient('localhost:'.$this->port, [ + 'force_new' => true, 'credentials' => Grpc\ChannelCredentials::createInsecure(), ], $intercept_channel3); @@ -304,6 +310,7 @@ class InterceptorTest extends PHPUnit_Framework_TestCase $intercept_channel = Grpc\Interceptor::intercept($this->channel, $change_request_interceptor); $client = new InterceptorClient('localhost:'.$this->port, [ + 'force_new' => true, 'credentials' => Grpc\ChannelCredentials::createInsecure(), ], $intercept_channel); @@ -354,6 +361,7 @@ class InterceptorTest extends PHPUnit_Framework_TestCase $intercept_channel = Grpc\Interceptor::intercept($this->channel, $channel_request_interceptor); $client = new InterceptorClient('localhost:'.$this->port, [ + 'force_new' => true, 'credentials' => Grpc\ChannelCredentials::createInsecure(), ], $intercept_channel); @@ -374,7 +382,10 @@ class InterceptorTest extends PHPUnit_Framework_TestCase { $channel = new Grpc\Channel( 'localhost:0', - ['credentials' => Grpc\ChannelCredentials::createInsecure()] + [ + 'force_new' => true, + 'credentials' => Grpc\ChannelCredentials::createInsecure() + ] ); $interceptor_channel = Grpc\Interceptor::intercept($channel, new Grpc\Interceptor()); $state = $interceptor_channel->getConnectivityState(); @@ -386,7 +397,10 @@ class InterceptorTest extends PHPUnit_Framework_TestCase { $channel = new Grpc\Channel( 'localhost:0', - ['credentials' => Grpc\ChannelCredentials::createInsecure()] + [ + 'force_new' => true, + 'credentials' => Grpc\ChannelCredentials::createInsecure() + ] ); $interceptor_channel = Grpc\Interceptor::intercept($channel, new Grpc\Interceptor()); $now = Grpc\Timeval::now(); @@ -402,7 +416,10 @@ class InterceptorTest extends PHPUnit_Framework_TestCase { $channel = new Grpc\Channel( 'localhost:0', - ['credentials' => Grpc\ChannelCredentials::createInsecure()] + [ + 'force_new' => true, + 'credentials' => Grpc\ChannelCredentials::createInsecure() + ] ); $interceptor_channel = Grpc\Interceptor::intercept($channel, new Grpc\Interceptor()); $this->assertNotNull($interceptor_channel); @@ -413,7 +430,10 @@ class InterceptorTest extends PHPUnit_Framework_TestCase { $channel = new Grpc\Channel( 'localhost:8888', - ['credentials' => Grpc\ChannelCredentials::createInsecure()] + [ + 'force_new' => true, + 'credentials' => Grpc\ChannelCredentials::createInsecure() + ] ); $interceptor_channel = Grpc\Interceptor::intercept($channel, new Grpc\Interceptor()); $target = $interceptor_channel->getTarget(); diff --git a/src/php/tests/unit_tests/SecureEndToEndTest.php b/src/php/tests/unit_tests/SecureEndToEndTest.php index dff4e878ea1..071598c4c19 100644 --- a/src/php/tests/unit_tests/SecureEndToEndTest.php +++ b/src/php/tests/unit_tests/SecureEndToEndTest.php @@ -34,6 +34,7 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase $this->channel = new Grpc\Channel( 'localhost:'.$this->port, [ + 'force_new' => true, 'grpc.ssl_target_name_override' => $this->host_override, 'grpc.default_authority' => $this->host_override, 'credentials' => $credentials, @@ -44,6 +45,7 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase public function tearDown() { $this->channel->close(); + unset($this->server); } public function testSimpleRequestBody() diff --git a/src/php/tests/unit_tests/ServerTest.php b/src/php/tests/unit_tests/ServerTest.php index ac6f2f03123..cab92e59419 100644 --- a/src/php/tests/unit_tests/ServerTest.php +++ b/src/php/tests/unit_tests/ServerTest.php @@ -55,7 +55,10 @@ class ServerTest extends PHPUnit_Framework_TestCase $port = $this->server->addHttp2Port('0.0.0.0:0'); $this->server->start(); $channel = new Grpc\Channel('localhost:'.$port, - ['credentials' => Grpc\ChannelCredentials::createInsecure()]); + [ + 'force_new' => true, + 'credentials' => Grpc\ChannelCredentials::createInsecure() + ]); $deadline = Grpc\Timeval::infFuture(); $call = new Grpc\Call($channel, 'dummy_method', $deadline);