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

Further updated EndToEndTest

parent d8bb9578
No related branches found
No related tags found
No related merge requests found
...@@ -182,8 +182,8 @@ PHP_METHOD(Server, request_call) { ...@@ -182,8 +182,8 @@ PHP_METHOD(Server, request_call) {
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, true));
add_property_string(result, "method", details.method, false); add_property_string(result, "method", details.method, true);
add_property_string(result, "host", details.host, false); add_property_string(result, "host", details.host, true);
add_property_zval(result, "absolute_deadline", add_property_zval(result, "absolute_deadline",
grpc_php_wrap_timeval(details.deadline)); grpc_php_wrap_timeval(details.deadline));
add_property_zval(result, "metadata", grpc_parse_metadata_array(&metadata)); add_property_zval(result, "metadata", grpc_parse_metadata_array(&metadata));
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
*/ */
class EndToEndTest extends PHPUnit_Framework_TestCase{ class EndToEndTest extends PHPUnit_Framework_TestCase{
public function setUp() { public function setUp() {
$this->server = new Grpc\Server($this->server_queue, []); $this->server = new Grpc\Server([]);
$port = $this->server->add_http2_port('0.0.0.0:0'); $port = $this->server->add_http2_port('0.0.0.0:0');
$this->channel = new Grpc\Channel('localhost:' . $port, []); $this->channel = new Grpc\Channel('localhost:' . $port, []);
$this->server->start(); $this->server->start();
...@@ -53,7 +53,7 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ ...@@ -53,7 +53,7 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
'dummy_method', 'dummy_method',
$deadline); $deadline);
$event = $this->call->start_batch([ $event = $call->start_batch([
Grpc\OP_SEND_INITIAL_METADATA => [], Grpc\OP_SEND_INITIAL_METADATA => [],
Grpc\OP_SEND_CLOSE_FROM_CLIENT => true Grpc\OP_SEND_CLOSE_FROM_CLIENT => true
]); ]);
...@@ -79,54 +79,17 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ ...@@ -79,54 +79,17 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
$this->assertTrue($event->send_status); $this->assertTrue($event->send_status);
$this->assertFalse($event->cancelled); $this->assertFalse($event->cancelled);
$tag = 1; $event = $call->start_batch([
$call->invoke($this->client_queue, $tag, $tag); Grpc\OP_RECV_INITIAL_METADATA => true,
$server_tag = 2; Grpc\OP_RECV_STATUS_ON_CLIENT => true,
]);
$call->writes_done($tag);
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
$this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
$this->assertSame(Grpc\OP_OK, $event->data);
// check that a server rpc new was received
$this->server->request_call($server_tag);
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
$this->assertSame(Grpc\SERVER_RPC_NEW, $event->type);
$server_call = $event->call;
$this->assertNotNull($server_call);
$server_call->server_accept($this->server_queue, $server_tag);
$server_call->server_end_initial_metadata();
// the server sends the status
$server_call->start_write_status(Grpc\STATUS_OK, $status_text, $server_tag);
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
$this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
$this->assertSame(Grpc\OP_OK, $event->data);
// the client gets CLIENT_METADATA_READ
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
$this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type);
// the client gets FINISHED $this->assertSame([], $event->metadata);
$event = $this->client_queue->next($deadline); $status = $event->status;
$this->assertNotNull($event); $this->assertSame([], $status->metadata);
$this->assertSame(Grpc\FINISHED, $event->type);
$status = $event->data;
$this->assertSame(Grpc\STATUS_OK, $status->code); $this->assertSame(Grpc\STATUS_OK, $status->code);
$this->assertSame($status_text, $status->details); $this->assertSame($status_text, $status->details);
// and the server gets FINISHED
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
$this->assertSame(Grpc\FINISHED, $event->type);
$status = $event->data;
unset($call); unset($call);
unset($server_call); unset($server_call);
} }
...@@ -140,79 +103,52 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ ...@@ -140,79 +103,52 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
$call = new Grpc\Call($this->channel, $call = new Grpc\Call($this->channel,
'dummy_method', 'dummy_method',
$deadline); $deadline);
$tag = 1;
$call->invoke($this->client_queue, $tag, $tag);
$server_tag = 2; $event = $call->start_batch([
Grpc\OP_SEND_INITIAL_METADATA => [],
Grpc\OP_SEND_CLOSE_FROM_CLIENT => true,
Grpc\OP_SEND_MESSAGE => $req_text
]);
// the client writes $this->assertTrue($event->send_metadata);
$call->start_write($req_text, $tag); $this->assertTrue($event->send_close);
$event = $this->client_queue->next($deadline); $this->assertTrue($event->send_message);
$this->assertNotNull($event);
$this->assertSame(Grpc\WRITE_ACCEPTED, $event->type);
// check that a server rpc new was received $event = $this->server->request_call();
$this->server->start(); $this->assertSame('dummy_method', $event->method);
$this->server->request_call($server_tag);
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
$this->assertSame(Grpc\SERVER_RPC_NEW, $event->type);
$server_call = $event->call; $server_call = $event->call;
$this->assertNotNull($server_call);
$server_call->server_accept($this->server_queue, $server_tag); $event = $server_call->start_batch([
Grpc\OP_SEND_INITIAL_METADATA => [],
$server_call->server_end_initial_metadata(); Grpc\OP_SEND_MESSAGE => $reply_text,
Grpc\OP_SEND_STATUS_FROM_SERVER => [
// start the server read 'metadata' => [],
$server_call->start_read($server_tag); 'code' => Grpc\STATUS_OK,
$event = $this->server_queue->next($deadline); 'details' => $status_text
$this->assertNotNull($event); ],
$this->assertSame(Grpc\READ, $event->type); Grpc\OP_RECV_MESSAGE => true,
$this->assertSame($req_text, $event->data); Grpc\OP_RECV_CLOSE_ON_SERVER => true,
]);
// the server replies
$server_call->start_write($reply_text, $server_tag); $this->assertTrue($event->send_metadata);
$event = $this->server_queue->next($deadline); $this->assertTrue($event->send_status);
$this->assertNotNull($event); $this->assertTrue($event->send_message);
$this->assertSame(Grpc\WRITE_ACCEPTED, $event->type); $this->assertFalse($event->cancelled);
$this->assertSame($req_text, $event->read);
// the client reads the metadata
$event = $this->client_queue->next($deadline); $event = $call->start_batch([
$this->assertNotNull($event); Grpc\OP_RECV_INITIAL_METADATA => true,
$this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type); Grpc\OP_RECV_MESSAGE => true,
Grpc\OP_RECV_STATUS_ON_CLIENT => true,
// the client reads the reply ]);
$call->start_read($tag);
$event = $this->client_queue->next($deadline); $this->assertSame([], $event->metadata);
$this->assertNotNull($event); $this->assertSame($reply_text, $event->read);
$this->assertSame(Grpc\READ, $event->type); $status = $event->status;
$this->assertSame($reply_text, $event->data); $this->assertSame([], $status->metadata);
// the client sends writes done
$call->writes_done($tag);
$event = $this->client_queue->next($deadline);
$this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
$this->assertSame(Grpc\OP_OK, $event->data);
// the server sends the status
$server_call->start_write_status(GRPC\STATUS_OK, $status_text, $server_tag);
$event = $this->server_queue->next($deadline);
$this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
$this->assertSame(Grpc\OP_OK, $event->data);
// the client gets FINISHED
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
$this->assertSame(Grpc\FINISHED, $event->type);
$status = $event->data;
$this->assertSame(Grpc\STATUS_OK, $status->code); $this->assertSame(Grpc\STATUS_OK, $status->code);
$this->assertSame($status_text, $status->details); $this->assertSame($status_text, $status->details);
// and the server gets FINISHED
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
$this->assertSame(Grpc\FINISHED, $event->type);
unset($call); unset($call);
unset($server_call); unset($server_call);
} }
......
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