aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/php/tests')
-rw-r--r--src/php/tests/unit_tests/CallCredentials2Test.php3
-rw-r--r--src/php/tests/unit_tests/CallCredentialsTest.php3
-rw-r--r--src/php/tests/unit_tests/CallTest.php3
-rw-r--r--src/php/tests/unit_tests/ChannelTest.php8
-rw-r--r--src/php/tests/unit_tests/EndToEndTest.php3
-rw-r--r--src/php/tests/unit_tests/PersistentChannelTest.php111
-rw-r--r--src/php/tests/unit_tests/SecureEndToEndTest.php3
-rw-r--r--src/php/tests/unit_tests/ServerTest.php3
-rw-r--r--src/php/tests/unit_tests/TimevalTest.php3
9 files changed, 140 insertions, 0 deletions
diff --git a/src/php/tests/unit_tests/CallCredentials2Test.php b/src/php/tests/unit_tests/CallCredentials2Test.php
index 1c7e0c0ff6..a462bfff56 100644
--- a/src/php/tests/unit_tests/CallCredentials2Test.php
+++ b/src/php/tests/unit_tests/CallCredentials2Test.php
@@ -46,6 +46,9 @@ class CallCredentials2Test extends PHPUnit_Framework_TestCase
{
unset($this->channel);
unset($this->server);
+ $channel_clean_persistent =
+ new Grpc\Channel('localhost:50010', []);
+ $channel_clean_persistent->cleanPersistentList();
}
public function callbackFunc($context)
diff --git a/src/php/tests/unit_tests/CallCredentialsTest.php b/src/php/tests/unit_tests/CallCredentialsTest.php
index 4b5721d76a..31046e6395 100644
--- a/src/php/tests/unit_tests/CallCredentialsTest.php
+++ b/src/php/tests/unit_tests/CallCredentialsTest.php
@@ -52,6 +52,9 @@ class CallCredentialsTest extends PHPUnit_Framework_TestCase
{
unset($this->channel);
unset($this->server);
+ $channel_clean_persistent =
+ new Grpc\Channel('localhost:50010', []);
+ $channel_clean_persistent->cleanPersistentList();
}
public function callbackFunc($context)
diff --git a/src/php/tests/unit_tests/CallTest.php b/src/php/tests/unit_tests/CallTest.php
index c5e1890a98..38c36ed19a 100644
--- a/src/php/tests/unit_tests/CallTest.php
+++ b/src/php/tests/unit_tests/CallTest.php
@@ -38,6 +38,9 @@ class CallTest extends PHPUnit_Framework_TestCase
public function tearDown()
{
$this->channel->close();
+ $channel_clean_persistent =
+ new Grpc\Channel('localhost:50010', []);
+ $channel_clean_persistent->cleanPersistentList();
}
public function testConstructor()
diff --git a/src/php/tests/unit_tests/ChannelTest.php b/src/php/tests/unit_tests/ChannelTest.php
index 5baff1fbd9..63d4193a8b 100644
--- a/src/php/tests/unit_tests/ChannelTest.php
+++ b/src/php/tests/unit_tests/ChannelTest.php
@@ -28,6 +28,9 @@ class ChannelTest extends PHPUnit_Framework_TestCase
if (!empty($this->channel)) {
$this->channel->close();
}
+ $channel_clean_persistent =
+ new Grpc\Channel('localhost:50010', []);
+ $channel_clean_persistent->cleanPersistentList();
}
public function testInsecureCredentials()
@@ -380,6 +383,11 @@ class ChannelTest extends PHPUnit_Framework_TestCase
// close channel1
$this->channel1->close();
+ // channel2 is now in SHUTDOWN state
+ $state = $this->channel2->getConnectivityState();
+ $this->assertEquals(GRPC\CHANNEL_FATAL_FAILURE, $state);
+
+ // calling it again will result in an exception because the
// channel is already closed
$state = $this->channel2->getConnectivityState();
}
diff --git a/src/php/tests/unit_tests/EndToEndTest.php b/src/php/tests/unit_tests/EndToEndTest.php
index b54f1d87c9..71a56d2b6e 100644
--- a/src/php/tests/unit_tests/EndToEndTest.php
+++ b/src/php/tests/unit_tests/EndToEndTest.php
@@ -29,6 +29,9 @@ class EndToEndTest extends PHPUnit_Framework_TestCase
public function tearDown()
{
$this->channel->close();
+ $channel_clean_persistent =
+ new Grpc\Channel('localhost:50010', []);
+ $channel_clean_persistent->cleanPersistentList();
}
public function testSimpleRequestBody()
diff --git a/src/php/tests/unit_tests/PersistentChannelTest.php b/src/php/tests/unit_tests/PersistentChannelTest.php
new file mode 100644
index 0000000000..31c6bbaf40
--- /dev/null
+++ b/src/php/tests/unit_tests/PersistentChannelTest.php
@@ -0,0 +1,111 @@
+<?php
+/*
+ *
+ * Copyright 2015 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.
+ *
+ */
+
+class PersistentListTest extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ }
+
+ public function tearDown()
+ {
+ $channel_clean_persistent =
+ new Grpc\Channel('localhost:50010', []);
+ $channel_clean_persistent->cleanPersistentList();
+ }
+
+ public function waitUntilNotIdle($channel) {
+ for ($i = 0; $i < 10; $i++) {
+ $now = Grpc\Timeval::now();
+ $deadline = $now->add(new Grpc\Timeval(1000));
+ if ($channel->watchConnectivityState(GRPC\CHANNEL_IDLE,
+ $deadline)) {
+ return true;
+ }
+ }
+ $this->assertTrue(false);
+ }
+
+ public function testPersistentChennelCreateOneChannel()
+ {
+ $this->channel1 = new Grpc\Channel('localhost:1', []);
+ $plist = $this->channel1->getPersistentList();
+ $this->assertEquals($plist['localhost:1']['target'], 'localhost:1');
+ $this->assertArrayHasKey('localhost:1', $plist);
+ $this->assertEquals($plist['localhost:1']['ref_count'], 1);
+ $this->assertEquals($plist['localhost:1']['connectivity_status'],
+ GRPC\CHANNEL_IDLE);
+ $this->assertEquals($plist['localhost:1']['is_valid'], 1);
+ $this->channel1->close();
+ }
+
+ public function testPersistentChennelStatusChange()
+ {
+ $this->channel1 = new Grpc\Channel('localhost:1', []);
+ $plist = $this->channel1->getPersistentList();
+ $this->assertEquals($plist['localhost:1']['connectivity_status'],
+ GRPC\CHANNEL_IDLE);
+ $this->assertEquals($plist['localhost:1']['is_valid'], 1);
+ $state = $this->channel1->getConnectivityState(true);
+
+ $this->waitUntilNotIdle($this->channel1);
+ $plist = $this->channel1->getPersistentList();
+ $this->assertEquals($plist['localhost:1']['connectivity_status'],
+ GRPC\CHANNEL_CONNECTING);
+ $this->assertEquals($plist['localhost:1']['is_valid'], 1);
+
+ $this->channel1->close();
+ }
+
+ public function testPersistentChennelCloseChannel()
+ {
+ $this->channel1 = new Grpc\Channel('localhost:1', []);
+ $plist = $this->channel1->getPersistentList();
+ $this->assertEquals($plist['localhost:1']['ref_count'], 1);
+ $this->channel1->close();
+ $plist = $this->channel1->getPersistentList();
+ $this->assertArrayNotHasKey('localhost:1', $plist);
+ }
+
+ public function testPersistentChannelSameHost()
+ {
+ $this->channel1 = new Grpc\Channel('localhost:1', []);
+ $this->channel2 = new Grpc\Channel('localhost:1', []);
+ //ref_count should be 2
+ $plist = $this->channel1->getPersistentList();
+ $this->assertArrayHasKey('localhost:1', $plist);
+ $this->assertEquals($plist['localhost:1']['ref_count'], 2);
+ $this->channel1->close();
+ $this->channel2->close();
+ }
+
+ public function testPersistentChannelDifferentHost()
+ {
+ $this->channel1 = new Grpc\Channel('localhost:1', []);
+ $this->channel2 = new Grpc\Channel('localhost:2', []);
+ $plist = $this->channel1->getPersistentList();
+ $this->assertArrayHasKey('localhost:1', $plist);
+ $this->assertArrayHasKey('localhost:2', $plist);
+ $this->assertEquals($plist['localhost:1']['ref_count'], 1);
+ $this->assertEquals($plist['localhost:2']['ref_count'], 1);
+ $this->channel1->close();
+ $this->channel2->close();
+ }
+
+}
diff --git a/src/php/tests/unit_tests/SecureEndToEndTest.php b/src/php/tests/unit_tests/SecureEndToEndTest.php
index dff4e878ea..e358abe2d2 100644
--- a/src/php/tests/unit_tests/SecureEndToEndTest.php
+++ b/src/php/tests/unit_tests/SecureEndToEndTest.php
@@ -44,6 +44,9 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase
public function tearDown()
{
$this->channel->close();
+ $channel_clean_persistent =
+ new Grpc\Channel('localhost:50010', []);
+ $channel_clean_persistent->cleanPersistentList();
}
public function testSimpleRequestBody()
diff --git a/src/php/tests/unit_tests/ServerTest.php b/src/php/tests/unit_tests/ServerTest.php
index fee9f1e644..d18feecefe 100644
--- a/src/php/tests/unit_tests/ServerTest.php
+++ b/src/php/tests/unit_tests/ServerTest.php
@@ -27,6 +27,9 @@ class ServerTest extends PHPUnit_Framework_TestCase
public function tearDown()
{
unset($this->server);
+ $channel_clean_persistent =
+ new Grpc\Channel('localhost:50010', []);
+ $channel_clean_persistent->cleanPersistentList();
}
public function testConstructorWithNull()
diff --git a/src/php/tests/unit_tests/TimevalTest.php b/src/php/tests/unit_tests/TimevalTest.php
index bc307ef7f1..be023adace 100644
--- a/src/php/tests/unit_tests/TimevalTest.php
+++ b/src/php/tests/unit_tests/TimevalTest.php
@@ -25,6 +25,9 @@ class TimevalTest extends PHPUnit_Framework_TestCase
public function tearDown()
{
unset($this->time);
+ $channel_clean_persistent =
+ new Grpc\Channel('localhost:50010', []);
+ $channel_clean_persistent->cleanPersistentList();
}
public function testConstructorWithInt()