Skip to content
Snippets Groups Projects
Commit d8bb9578 authored by murgatroid99's avatar murgatroid99
Browse files

Fixed some tests for new API

parent afd541cb
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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);
}
}
<?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);
}
}
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment