diff options
author | murgatroid99 <mlumish@google.com> | 2015-03-11 09:18:06 -0700 |
---|---|---|
committer | murgatroid99 <mlumish@google.com> | 2015-03-11 09:18:06 -0700 |
commit | d8bb9578efa3ff6d287ec7bf735dc97b636b9f04 (patch) | |
tree | 93a63d09b01b51c4a9caf2618031e26bda865671 /src | |
parent | afd541cbd35d873a98aee02ed0bd8177f3343410 (diff) |
Fixed some tests for new API
Diffstat (limited to 'src')
-rw-r--r-- | src/php/ext/grpc/call.c | 8 | ||||
-rwxr-xr-x | src/php/tests/unit_tests/CallTest.php | 62 | ||||
-rwxr-xr-x | src/php/tests/unit_tests/CompletionQueueTest.php | 46 | ||||
-rwxr-xr-x | src/php/tests/unit_tests/EndToEndTest.php | 31 |
4 files changed, 52 insertions, 95 deletions
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index b1ac1b7640..8f5ec24776 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -287,6 +287,8 @@ PHP_METHOD(Call, start_batch) { zval *recv_status; grpc_metadata_array_init(&metadata); grpc_metadata_array_init(&trailing_metadata); + grpc_metadata_array_init(&recv_metadata); + grpc_metadata_array_init(&recv_trailing_metadata); MAKE_STD_ZVAL(result); object_init(result); /* "a" == 1 array */ @@ -458,13 +460,7 @@ PHP_METHOD(Call, start_batch) { } } cleanup: - if (metadata.metadata != NULL) { - gpr_free(metadata.metadata); - } grpc_metadata_array_destroy(&metadata); - if (trailing_metadata.metadata != NULL) { - gpr_free(trailing_metadata.metadata); - } grpc_metadata_array_destroy(&trailing_metadata); grpc_metadata_array_destroy(&recv_metadata); grpc_metadata_array_destroy(&recv_trailing_metadata); diff --git a/src/php/tests/unit_tests/CallTest.php b/src/php/tests/unit_tests/CallTest.php index 8bb0927f21..d361ce0030 100755 --- a/src/php/tests/unit_tests/CallTest.php +++ b/src/php/tests/unit_tests/CallTest.php @@ -36,65 +36,47 @@ class CallTest extends PHPUnit_Framework_TestCase{ static $port; public static function setUpBeforeClass() { - $cq = new Grpc\CompletionQueue(); - self::$server = new Grpc\Server($cq, []); + self::$server = new Grpc\Server([]); self::$port = self::$server->add_http2_port('0.0.0.0:0'); } public function setUp() { - $this->cq = new Grpc\CompletionQueue(); $this->channel = new Grpc\Channel('localhost:' . self::$port, []); $this->call = new Grpc\Call($this->channel, '/foo', Grpc\Timeval::inf_future()); } - /** - * @expectedException LogicException - * @expectedExceptionCode Grpc\CALL_ERROR_INVALID_FLAGS - * @expectedExceptionMessage invoke - */ - public function testInvokeRejectsBadFlags() { - $this->call->invoke($this->cq, 0, 0, 0xDEADBEEF); - } - - /** - * @expectedException LogicException - * @expectedExceptionCode Grpc\CALL_ERROR_NOT_ON_CLIENT - * @expectedExceptionMessage server_accept - */ - public function testServerAcceptFailsCorrectly() { - $this->call->server_accept($this->cq, 0); - } - - /* These test methods with assertTrue(true) at the end just check that the - method calls completed without errors. PHPUnit warns for tests with no - asserts, and this avoids that warning without changing the meaning of the - tests */ - public function testAddEmptyMetadata() { - $this->call->add_metadata([], 0); - /* Dummy assert: Checks that the previous call completed without error */ - $this->assertTrue(true); + $batch = [ + Grpc\OP_SEND_INITIAL_METADATA => [] + ]; + $result = $this->call->start_batch($batch); + $this->assertTrue($result->send_metadata); } public function testAddSingleMetadata() { - $this->call->add_metadata(['key' => ['value']], 0); - /* Dummy assert: Checks that the previous call completed without error */ - $this->assertTrue(true); + $batch = [ + Grpc\OP_SEND_INITIAL_METADATA => ['key' => ['value']] + ]; + $result = $this->call->start_batch($batch); + $this->assertTrue($result->send_metadata); } public function testAddMultiValueMetadata() { - $this->call->add_metadata(['key' => ['value1', 'value2']], 0); - /* Dummy assert: Checks that the previous call completed without error */ - $this->assertTrue(true); + $batch = [ + Grpc\OP_SEND_INITIAL_METADATA => ['key' => ['value1', 'value2']] + ]; + $result = $this->call->start_batch($batch); + $this->assertTrue($result->send_metadata); } public function testAddSingleAndMultiValueMetadata() { - $this->call->add_metadata( - ['key1' => ['value1'], - 'key2' => ['value2', 'value3']], 0); - /* Dummy assert: Checks that the previous call completed without error */ - $this->assertTrue(true); + $batch = [ + Grpc\OP_SEND_INITIAL_METADATA => ['key1' => ['value1'], + 'key2' => ['value2', 'value3']] + ]; + $result = $this->call->start_batch($batch); + $this->assertTrue($result->send_metadata); } } diff --git a/src/php/tests/unit_tests/CompletionQueueTest.php b/src/php/tests/unit_tests/CompletionQueueTest.php deleted file mode 100755 index 76ee61dfe8..0000000000 --- a/src/php/tests/unit_tests/CompletionQueueTest.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -class CompletionQueueTest extends PHPUnit_Framework_TestCase{ - public function testNextReturnsNullWithNoCall() { - $cq = new Grpc\CompletionQueue(); - $event = $cq->next(Grpc\Timeval::zero()); - $this->assertNull($event); - } - - public function testPluckReturnsNullWithNoCall() { - $cq = new Grpc\CompletionQueue(); - $event = $cq->pluck(0, Grpc\Timeval::zero()); - $this->assertNull($event); - } -} diff --git a/src/php/tests/unit_tests/EndToEndTest.php b/src/php/tests/unit_tests/EndToEndTest.php index 0cbc506c8e..076d449362 100755 --- a/src/php/tests/unit_tests/EndToEndTest.php +++ b/src/php/tests/unit_tests/EndToEndTest.php @@ -33,11 +33,10 @@ */ class EndToEndTest extends PHPUnit_Framework_TestCase{ public function setUp() { - $this->client_queue = new Grpc\CompletionQueue(); - $this->server_queue = new Grpc\CompletionQueue(); $this->server = new Grpc\Server($this->server_queue, []); $port = $this->server->add_http2_port('0.0.0.0:0'); $this->channel = new Grpc\Channel('localhost:' . $port, []); + $this->server->start(); } public function tearDown() { @@ -53,6 +52,33 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ $call = new Grpc\Call($this->channel, 'dummy_method', $deadline); + + $event = $this->call->start_batch([ + Grpc\OP_SEND_INITIAL_METADATA => [], + Grpc\OP_SEND_CLOSE_FROM_CLIENT => true + ]); + + $this->assertTrue($event->send_metadata); + $this->assertTrue($event->send_close); + + $event = $this->server->request_call(); + $this->assertSame('dummy_method', $event->method); + $server_call = $event->call; + + $event = $server_call->start_batch([ + Grpc\OP_SEND_INITIAL_METADATA => [], + Grpc\OP_SEND_STATUS_FROM_SERVER => [ + 'metadata' => [], + 'code' => Grpc\STATUS_OK, + 'details' => $status_text + ], + Grpc\OP_RECV_CLOSE_ON_SERVER => true + ]); + + $this->assertTrue($event->send_metadata); + $this->assertTrue($event->send_status); + $this->assertFalse($event->cancelled); + $tag = 1; $call->invoke($this->client_queue, $tag, $tag); $server_tag = 2; @@ -64,7 +90,6 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ $this->assertSame(Grpc\OP_OK, $event->data); // check that a server rpc new was received - $this->server->start(); $this->server->request_call($server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); |