Switched to binding servers to port 0 in tests

pull/376/head
murgatroid99 10 years ago
parent 8c0596edca
commit d96db79b92
  1. 4
      src/php/ext/grpc/server.c
  2. 5
      src/php/tests/unit_tests/CallTest.php
  3. 6
      src/php/tests/unit_tests/EndToEndTest.php
  4. 5
      src/php/tests/unit_tests/SecureEndToEndTest.php
  5. 6
      src/php/tests/util/port_picker.php

@ -146,7 +146,7 @@ PHP_METHOD(Server, add_http2_port) {
"add_http2_port expects a string", 1 TSRMLS_CC); "add_http2_port expects a string", 1 TSRMLS_CC);
return; return;
} }
RETURN_BOOL(grpc_server_add_http2_port(server->wrapped, addr)); RETURN_LONG(grpc_server_add_http2_port(server->wrapped, addr));
} }
PHP_METHOD(Server, add_secure_http2_port) { PHP_METHOD(Server, add_secure_http2_port) {
@ -161,7 +161,7 @@ PHP_METHOD(Server, add_secure_http2_port) {
"add_http2_port expects a string", 1 TSRMLS_CC); "add_http2_port expects a string", 1 TSRMLS_CC);
return; return;
} }
RETURN_BOOL(grpc_server_add_secure_http2_port(server->wrapped, addr)); RETURN_LONG(grpc_server_add_secure_http2_port(server->wrapped, addr));
} }
/** /**

@ -1,16 +1,17 @@
<?php <?php
class CallTest extends PHPUnit_Framework_TestCase{ class CallTest extends PHPUnit_Framework_TestCase{
static $server; static $server;
static $port;
public static function setUpBeforeClass() { public static function setUpBeforeClass() {
$cq = new Grpc\CompletionQueue(); $cq = new Grpc\CompletionQueue();
self::$server = new Grpc\Server($cq, []); self::$server = new Grpc\Server($cq, []);
self::$server->add_http2_port('localhost:9001'); self::$port = self::$server->add_http2_port('0.0.0.0:0');
} }
public function setUp() { public function setUp() {
$this->cq = new Grpc\CompletionQueue(); $this->cq = new Grpc\CompletionQueue();
$this->channel = new Grpc\Channel('localhost:9001', []); $this->channel = new Grpc\Channel('localhost:' . self::$port, []);
$this->call = new Grpc\Call($this->channel, $this->call = new Grpc\Call($this->channel,
'/foo', '/foo',
Grpc\Timeval::inf_future()); Grpc\Timeval::inf_future());

@ -1,13 +1,11 @@
<?php <?php
require __DIR__ . '/../util/port_picker.php';
class EndToEndTest extends PHPUnit_Framework_TestCase{ class EndToEndTest extends PHPUnit_Framework_TestCase{
public function setUp() { public function setUp() {
$this->client_queue = new Grpc\CompletionQueue(); $this->client_queue = new Grpc\CompletionQueue();
$this->server_queue = new Grpc\CompletionQueue(); $this->server_queue = new Grpc\CompletionQueue();
$this->server = new Grpc\Server($this->server_queue, []); $this->server = new Grpc\Server($this->server_queue, []);
$address = '127.0.0.1:' . getNewPort(); $port = $this->server->add_http2_port('0.0.0.0:0');
$this->server->add_http2_port($address); $this->channel = new Grpc\Channel('localhost:' . $port, []);
$this->channel = new Grpc\Channel($address, []);
} }
public function tearDown() { public function tearDown() {

@ -11,10 +11,9 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
file_get_contents(dirname(__FILE__) . '/../data/server1.pem')); file_get_contents(dirname(__FILE__) . '/../data/server1.pem'));
$this->server = new Grpc\Server($this->server_queue, $this->server = new Grpc\Server($this->server_queue,
['credentials' => $server_credentials]); ['credentials' => $server_credentials]);
$address = '127.0.0.1:' . getNewPort(); $port = $this->server->add_secure_http2_port('0.0.0.0:0');
$this->server->add_secure_http2_port($address);
$this->channel = new Grpc\Channel( $this->channel = new Grpc\Channel(
$address, 'localhost:' . $port,
[ [
'grpc.ssl_target_name_override' => 'foo.test.google.com', 'grpc.ssl_target_name_override' => 'foo.test.google.com',
'credentials' => $credentials 'credentials' => $credentials

@ -1,6 +0,0 @@
<?php
function getNewPort() {
static $port = 10000;
$port += 1;
return $port;
}
Loading…
Cancel
Save