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

EndToEndTest now works

parent 4eb8bba7
No related branches found
No related tags found
No related merge requests found
...@@ -60,18 +60,18 @@ ...@@ -60,18 +60,18 @@
void free_wrapped_grpc_call(void *object TSRMLS_DC) { void free_wrapped_grpc_call(void *object TSRMLS_DC) {
wrapped_grpc_call *call = (wrapped_grpc_call *)object; wrapped_grpc_call *call = (wrapped_grpc_call *)object;
grpc_event *event; grpc_event *event;
if (call->queue != NULL) { if (call->owned && call->wrapped != NULL) {
grpc_completion_queue_shutdown(call->queue); if (call->queue != NULL) {
event = grpc_completion_queue_next(call->queue, gpr_inf_future); grpc_completion_queue_shutdown(call->queue);
while (event != NULL) {
if (event->type == GRPC_QUEUE_SHUTDOWN) {
break;
}
event = grpc_completion_queue_next(call->queue, gpr_inf_future); event = grpc_completion_queue_next(call->queue, gpr_inf_future);
while (event != NULL) {
if (event->type == GRPC_QUEUE_SHUTDOWN) {
break;
}
event = grpc_completion_queue_next(call->queue, gpr_inf_future);
}
grpc_completion_queue_destroy(call->queue);
} }
grpc_completion_queue_destroy(call->queue);
}
if (call->owned && call->wrapped != NULL) {
grpc_call_destroy(call->wrapped); grpc_call_destroy(call->wrapped);
} }
efree(call); efree(call);
...@@ -98,14 +98,15 @@ zend_object_value create_wrapped_grpc_call(zend_class_entry *class_type ...@@ -98,14 +98,15 @@ zend_object_value create_wrapped_grpc_call(zend_class_entry *class_type
/* Wraps a grpc_call struct in a PHP object. Owned indicates whether the struct /* Wraps a grpc_call struct in a PHP object. Owned indicates whether the struct
should be destroyed at the end of the object's lifecycle */ should be destroyed at the end of the object's lifecycle */
zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned) { zval *grpc_php_wrap_call(grpc_call *wrapped, grpc_completion_queue *queue,
bool owned) {
zval *call_object; zval *call_object;
MAKE_STD_ZVAL(call_object); MAKE_STD_ZVAL(call_object);
object_init_ex(call_object, grpc_ce_call); object_init_ex(call_object, grpc_ce_call);
wrapped_grpc_call *call = wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(call_object TSRMLS_CC); (wrapped_grpc_call *)zend_object_store_get_object(call_object TSRMLS_CC);
call->wrapped = wrapped; call->wrapped = wrapped;
call->queue = grpc_completion_queue_create(); call->queue = queue;
return call_object; return call_object;
} }
...@@ -276,7 +277,7 @@ PHP_METHOD(Call, start_batch) { ...@@ -276,7 +277,7 @@ PHP_METHOD(Call, start_batch) {
grpc_metadata_array recv_trailing_metadata; grpc_metadata_array recv_trailing_metadata;
grpc_status_code status; grpc_status_code status;
char *status_details = NULL; char *status_details = NULL;
size_t status_details_capacity; size_t status_details_capacity = 0;
grpc_byte_buffer *message; grpc_byte_buffer *message;
int cancelled; int cancelled;
grpc_call_error error; grpc_call_error error;
...@@ -406,14 +407,15 @@ PHP_METHOD(Call, start_batch) { ...@@ -406,14 +407,15 @@ PHP_METHOD(Call, start_batch) {
ops[op_num].op = (grpc_op_type)index; ops[op_num].op = (grpc_op_type)index;
op_num++; op_num++;
} }
error = grpc_call_start_batch(call->wrapped, ops, op_num, NULL); error = grpc_call_start_batch(call->wrapped, ops, op_num, call->wrapped);
if (error != GRPC_CALL_OK) { if (error != GRPC_CALL_OK) {
zend_throw_exception(spl_ce_LogicException, zend_throw_exception(spl_ce_LogicException,
"start_batch was called incorrectly", "start_batch was called incorrectly",
(long)error TSRMLS_CC); (long)error TSRMLS_CC);
goto cleanup; goto cleanup;
} }
event = grpc_completion_queue_pluck(call->queue, NULL, gpr_inf_future); event = grpc_completion_queue_pluck(call->queue, call->wrapped,
gpr_inf_future);
if (event->data.op_complete != GRPC_OP_OK) { if (event->data.op_complete != GRPC_OP_OK) {
zend_throw_exception(spl_ce_LogicException, zend_throw_exception(spl_ce_LogicException,
"The batch failed for some reason", "The batch failed for some reason",
...@@ -449,7 +451,7 @@ PHP_METHOD(Call, start_batch) { ...@@ -449,7 +451,7 @@ PHP_METHOD(Call, start_batch) {
add_property_zval(recv_status, "metadata", add_property_zval(recv_status, "metadata",
grpc_parse_metadata_array(&recv_trailing_metadata)); grpc_parse_metadata_array(&recv_trailing_metadata));
add_property_long(recv_status, "code", status); add_property_long(recv_status, "code", status);
add_property_string(recv_status, "details", status_details, false); add_property_string(recv_status, "details", status_details, true);
add_property_zval(result, "status", recv_status); add_property_zval(result, "status", recv_status);
break; break;
case GRPC_OP_RECV_CLOSE_ON_SERVER: case GRPC_OP_RECV_CLOSE_ON_SERVER:
......
...@@ -61,7 +61,8 @@ typedef struct wrapped_grpc_call { ...@@ -61,7 +61,8 @@ typedef struct wrapped_grpc_call {
void grpc_init_call(TSRMLS_D); void grpc_init_call(TSRMLS_D);
/* Creates a Call object that wraps the given grpc_call struct */ /* Creates a Call object that wraps the given grpc_call struct */
zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned); zval *grpc_php_wrap_call(grpc_call *wrapped, grpc_completion_queue *queue,
bool owned);
/* Creates and returns a PHP associative array of metadata from a C array of /* Creates and returns a PHP associative array of metadata from a C array of
* call metadata */ * call metadata */
......
...@@ -181,7 +181,8 @@ PHP_METHOD(Server, request_call) { ...@@ -181,7 +181,8 @@ PHP_METHOD(Server, request_call) {
1 TSRMLS_CC); 1 TSRMLS_CC);
goto cleanup; goto cleanup;
} }
add_property_zval(result, "call", grpc_php_wrap_call(call, true)); add_property_zval(result, "call", grpc_php_wrap_call(call, server->queue,
true));
add_property_string(result, "method", details.method, true); add_property_string(result, "method", details.method, true);
add_property_string(result, "host", details.host, true); add_property_string(result, "host", details.host, true);
add_property_zval(result, "absolute_deadline", add_property_zval(result, "absolute_deadline",
......
...@@ -42,8 +42,6 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ ...@@ -42,8 +42,6 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
public function tearDown() { public function tearDown() {
unset($this->channel); unset($this->channel);
unset($this->server); unset($this->server);
unset($this->client_queue);
unset($this->server_queue);
} }
public function testSimpleRequestBody() { public function testSimpleRequestBody() {
...@@ -63,6 +61,7 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ ...@@ -63,6 +61,7 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
$event = $this->server->request_call(); $event = $this->server->request_call();
$this->assertSame('dummy_method', $event->method); $this->assertSame('dummy_method', $event->method);
$this->assertSame([], $event->metadata);
$server_call = $event->call; $server_call = $event->call;
$event = $server_call->start_batch([ $event = $server_call->start_batch([
...@@ -81,8 +80,8 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ ...@@ -81,8 +80,8 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
$event = $call->start_batch([ $event = $call->start_batch([
Grpc\OP_RECV_INITIAL_METADATA => true, Grpc\OP_RECV_INITIAL_METADATA => true,
Grpc\OP_RECV_STATUS_ON_CLIENT => true, Grpc\OP_RECV_STATUS_ON_CLIENT => true
]); ]);
$this->assertSame([], $event->metadata); $this->assertSame([], $event->metadata);
$status = $event->status; $status = $event->status;
...@@ -134,7 +133,7 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ ...@@ -134,7 +133,7 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
$this->assertTrue($event->send_status); $this->assertTrue($event->send_status);
$this->assertTrue($event->send_message); $this->assertTrue($event->send_message);
$this->assertFalse($event->cancelled); $this->assertFalse($event->cancelled);
$this->assertSame($req_text, $event->read); $this->assertSame($req_text, $event->message);
$event = $call->start_batch([ $event = $call->start_batch([
Grpc\OP_RECV_INITIAL_METADATA => true, Grpc\OP_RECV_INITIAL_METADATA => true,
...@@ -143,7 +142,7 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ ...@@ -143,7 +142,7 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
]); ]);
$this->assertSame([], $event->metadata); $this->assertSame([], $event->metadata);
$this->assertSame($reply_text, $event->read); $this->assertSame($reply_text, $event->message);
$status = $event->status; $status = $event->status;
$this->assertSame([], $status->metadata); $this->assertSame([], $status->metadata);
$this->assertSame(Grpc\STATUS_OK, $status->code); $this->assertSame(Grpc\STATUS_OK, $status->code);
......
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