diff --git a/.gitattributes b/.gitattributes index 5a914d82cd..fb81a4dafd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,5 +3,4 @@ /.gitignore export-ignore /tests export-ignore /cloud-apis export-ignore -grpc-gcp-bootstrap.php export-ignore -phpunit-grpc-gcp.xml.dist export-ignore +phpunit.xml.dist export-ignore diff --git a/.github/release-please.yml b/.github/release-please.yml new file mode 100644 index 0000000000..ddc69395da --- /dev/null +++ b/.github/release-please.yml @@ -0,0 +1,3 @@ +releaseType: simple +handleGHRelease: true +primaryBranch: main diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000000..875fcce475 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,30 @@ +name: Test Suite +on: + push: + branches: + - master + pull_request: +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + php: [ 7.4, "8.0", 8.1, 8.2 ] + name: "PHP ${{ matrix.php }} Unit Test" + steps: + - uses: actions/checkout@v2 + - uses: codecov/codecov-action@v1 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: pecl + extensions: grpc-1.49.0 + - name: Install composer dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 10 + max_attempts: 3 + command: composer install + - name: Run PHPUnit + run: vendor/bin/phpunit -v diff --git a/composer.json b/composer.json index d26dc20d4c..ad1f98228d 100644 --- a/composer.json +++ b/composer.json @@ -3,14 +3,14 @@ "description": "gRPC GCP library for channel management", "license": "Apache-2.0", "require": { - "php": ">=5.5.0", + "php": "^7.4||^8.0", "google/protobuf": "^v3.3.0", "grpc/grpc": "^v1.13.0", "google/auth": "^1.3", "psr/cache": "^1.0.1||^2.0.0||^3.0.0" }, "require-dev": { - "phpunit/phpunit": "4.8.36", + "phpunit/phpunit": "^9.0", "google/cloud-spanner": "^1.7" }, "autoload": { diff --git a/grpc-gcp-bootstrap.php b/grpc-gcp-bootstrap.php deleted file mode 100644 index defe584820..0000000000 --- a/grpc-gcp-bootstrap.php +++ /dev/null @@ -1,2 +0,0 @@ - - - ./tests/grpc-gcp + + ./tests/grpc-gcp/grpc_unit_test diff --git a/tests/grpc-gcp/BasicTest.php b/tests/grpc-gcp/BasicTest.php index d99f7c81e3..f6a9462a9a 100644 --- a/tests/grpc-gcp/BasicTest.php +++ b/tests/grpc-gcp/BasicTest.php @@ -22,20 +22,11 @@ use Google\Auth\ApplicationDefaultCredentials; use Google\Cloud\Spanner\V1\ExecuteSqlRequest; use Google\Cloud\Spanner\V1\ListSessionsRequest; +use PHPUnit\Framework\TestCase; -class BasicTest extends PHPUnit_Framework_TestCase +class BasicTest extends TestCase { - public function setUp() - { - } - - - public function tearDown() - { - } - - - public function createStub($max_channels = 10, $max_streams = 1) + public function createGrpcStub($max_channels = 10, $max_streams = 1) { $this->_DEFAULT_MAX_CHANNELS_PER_TARGET = $max_channels; $this->_WATER_MARK = $max_streams; @@ -75,7 +66,7 @@ public function assertStatusOk($status) // Test CreateSession Reuse Channel public function testCreateSessionReuseChannel() { - $this->createStub(); + $this->createGrpcStub(); for ($i = 0; $i < $this->_DEFAULT_MAX_CHANNELS_PER_TARGET; $i++) { $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); @@ -94,7 +85,7 @@ public function testCreateSessionReuseChannel() // Test CreateSession New Channel public function testCreateSessionNewChannel() { - $this->createStub(); + $this->createGrpcStub(); $rpc_calls = array(); for ($i = 0; $i < $this->_DEFAULT_MAX_CHANNELS_PER_TARGET; $i++) { $create_session_request = new CreateSessionRequest(); @@ -139,7 +130,7 @@ public function testCreateSessionNewChannel() // Test Create List Delete Session public function testCreateListDeleteSession() { - $this->createStub(); + $this->createGrpcStub(); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $this->stub->CreateSession($create_session_request); @@ -183,7 +174,7 @@ public function testCreateListDeleteSession() // Test Execute Sql public function testExecuteSql() { - $this->createStub(); + $this->createGrpcStub(); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $this->stub->CreateSession($create_session_request); @@ -224,7 +215,7 @@ public function testExecuteSql() // Test Execute Streaming Sql public function testExecuteStreamingSql() { - $this->createStub(); + $this->createGrpcStub(); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $this->stub->CreateSession($create_session_request); @@ -254,7 +245,7 @@ public function testExecuteStreamingSql() // Test Concurrent Streams Watermark public function testConcurrentStreamsWatermark() { - $this->createStub(10, 2); + $this->createGrpcStub(10, 2); $sql_cmd = "select id from $this->table"; $result = ['payload']; $exec_sql_calls = array(); @@ -346,7 +337,7 @@ public function testConcurrentStreamsWatermark() // Test More Than 100 Concurrent Stream public function testHundredConcurrentStream() { - $this->createStub(10, 100); + $this->createGrpcStub(10, 100); $sql_cmd = "select id from $this->table"; $result = ['payload']; $exec_sql_calls = array(); diff --git a/tests/grpc-gcp/ChannelManagementNoConfigTest.php b/tests/grpc-gcp/ChannelManagementNoConfigTest.php index acf9aee2ea..d8a3d3a47b 100644 --- a/tests/grpc-gcp/ChannelManagementNoConfigTest.php +++ b/tests/grpc-gcp/ChannelManagementNoConfigTest.php @@ -22,20 +22,11 @@ use Google\Auth\ApplicationDefaultCredentials; use Google\Cloud\Spanner\V1\ExecuteSqlRequest; use Google\Cloud\Spanner\V1\ListSessionsRequest; +use PHPUnit\Framework\TestCase; -class ChannelManagementNoConfigTest extends PHPUnit_Framework_TestCase +class ChannelManagementNoConfigTest extends TestCase { - public function setUp() - { - } - - - public function tearDown() - { - } - - - public function createStub($max_channels = 10, $max_streams = 1) + public function createGrpcStub($max_channels = 10, $max_streams = 1) { $this->_DEFAULT_MAX_CHANNELS_PER_TARGET = $max_channels; $this->_WATER_MARK = $max_streams; @@ -75,7 +66,7 @@ public function assertStatusOk($status) // Test CreateSession Reuse Channel public function testCreateSessionReuseChannel() { - $this->createStub(); + $this->createGrpcStub(); for ($i = 0; $i < $this->_DEFAULT_MAX_CHANNELS_PER_TARGET; $i++) { $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); @@ -96,7 +87,7 @@ public function testCreateSessionReuseChannel() // Test CreateSession New Channel public function testCreateSessionNewChannel() { - $this->createStub(); + $this->createGrpcStub(); $rpc_calls = array(); // All RPCs are sent by the first channel created. Because the numbers of streams // are less than 100. @@ -131,7 +122,7 @@ public function testCreateSessionNewChannel() // Test Create List Delete Session public function testCreateListDeleteSession() { - $this->createStub(); + $this->createGrpcStub(); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $this->stub->CreateSession($create_session_request); @@ -176,7 +167,7 @@ public function testCreateListDeleteSession() // Test Execute Sql public function testExecuteSql() { - $this->createStub(); + $this->createGrpcStub(); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $this->stub->CreateSession($create_session_request); @@ -218,7 +209,7 @@ public function testExecuteSql() // Test Execute Streaming Sql public function testExecuteStreamingSql() { - $this->createStub(); + $this->createGrpcStub(); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $this->stub->CreateSession($create_session_request); @@ -248,7 +239,7 @@ public function testExecuteStreamingSql() // Test Concurrent Streams Watermark public function testConcurrentStreamsWatermark() { - $this->createStub(10, 2); + $this->createGrpcStub(10, 2); $sql_cmd = "select id from $this->table"; $result = ['payload']; $exec_sql_calls = array(); @@ -340,7 +331,7 @@ public function testConcurrentStreamsWatermark() // Test More Than 100 Concurrent Stream public function testHundredConcurrentStream() { - $this->createStub(10, 100); + $this->createGrpcStub(10, 100); $sql_cmd = "select id from $this->table"; $result = ['payload']; $exec_sql_calls = array(); diff --git a/tests/grpc-gcp/ReproduceTest.php b/tests/grpc-gcp/ReproduceTest.php index 016b35d69e..165b8b2240 100644 --- a/tests/grpc-gcp/ReproduceTest.php +++ b/tests/grpc-gcp/ReproduceTest.php @@ -21,23 +21,18 @@ use Google\Auth\ApplicationDefaultCredentials; use Google\Cloud\Spanner\V1\ExecuteSqlRequest; use Google\Cloud\Spanner\V1\ListSessionsRequest; +use PHPUnit\Framework\TestCase; -class ReproduceTest extends PHPUnit_Framework_TestCase +class ReproduceTest extends TestCase { - public function setUp() + public function setUp(): void { $this->_DEFAULT_MAX_CHANNELS_PER_TARGET = 10; $this->_WATER_MARK = 100; $this->database = 'projects/grpc-gcp/instances/sample/databases/benchmark'; } - - public function tearDown() - { - } - - - public function createStub($enable_gcp = true) + public function createGrpcStub($enable_gcp = true) { $credentials = \Grpc\ChannelCredentials::createSsl(); $auth = ApplicationDefaultCredentials::getCredentials(); @@ -120,7 +115,7 @@ public function waitForStreamingResponses($calls, $number) public function testGrpcWithoutGCPSuccessLessThan100Streams() { - $stub_no_gcp = $this->createStub(false); + $stub_no_gcp = $this->createGrpcStub(false); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $stub_no_gcp->CreateSession($create_session_request); @@ -141,7 +136,7 @@ public function testGrpcWithoutGCPSuccessLessThan100Streams() public function testGrpcWithoutGCPWillHangMoreThan100Streams() { - $stub_no_gcp = $this->createStub(false); + $stub_no_gcp = $this->createGrpcStub(false); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $stub_no_gcp->CreateSession($create_session_request); @@ -168,7 +163,7 @@ public function testGrpcWithoutGCPWillHangMoreThan100Streams() public function testGrpcWithGCPSuccessLessThan100Streams() { - $stub_no_gcp = $this->createStub(true); + $stub_no_gcp = $this->createGrpcStub(true); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $stub_no_gcp->CreateSession($create_session_request); @@ -189,7 +184,7 @@ public function testGrpcWithGCPSuccessLessThan100Streams() public function testGrpcWithGCPSuccessMoreThan100Streams() { - $stub_no_gcp = $this->createStub(true); + $stub_no_gcp = $this->createGrpcStub(true); $create_session_request = new CreateSessionRequest(); $create_session_request->setDatabase($this->database); $create_session_call = $stub_no_gcp->CreateSession($create_session_request); diff --git a/tests/grpc-gcp/grpc_unit_test/ChannelTest.php b/tests/grpc-gcp/grpc_unit_test/ChannelTest.php index 33b31d59d8..d9c625f6c4 100644 --- a/tests/grpc-gcp/grpc_unit_test/ChannelTest.php +++ b/tests/grpc-gcp/grpc_unit_test/ChannelTest.php @@ -16,13 +16,13 @@ * limitations under the License. * */ -class ChannelTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - } - public function tearDown() +use PHPUnit\Framework\TestCase; +use InvalidArgumentException; + +class ChannelTest extends TestCase +{ + public function tearDown(): void { if (!empty($this->channel)) { $this->channel->close(); @@ -100,67 +100,53 @@ public function testClose() $this->channel->close(); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidConstructorWithNull() { + $this->expectException(InvalidArgumentException::class); $this->channel = new Grpc\Gcp\GcpExtensionChannel(); $this->assertNull($this->channel); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidConstructorWith() { + $this->expectException(InvalidArgumentException::class); $this->channel = new Grpc\Gcp\GcpExtensionChannel('localhost:50008', 'invalid'); $this->assertNull($this->channel); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidCredentials() { + $this->expectException(InvalidArgumentException::class); $this->channel = new Grpc\Gcp\GcpExtensionChannel('localhost:50009', ['credentials' => new Grpc\Timeval(100)]); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidOptionsArray() { + $this->expectException(InvalidArgumentException::class); $this->channel = new Grpc\Gcp\GcpExtensionChannel('localhost:50010', ['abc' => []]); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidGetConnectivityStateWithArray() { + $this->expectException(InvalidArgumentException::class); $this->channel = new Grpc\Gcp\GcpExtensionChannel('localhost:50011', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); $this->channel->getConnectivityState([]); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidWatchConnectivityState() { + $this->expectException(InvalidArgumentException::class); $this->channel = new Grpc\Gcp\GcpExtensionChannel('localhost:50012', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); $this->channel->watchConnectivityState([]); } - /** - * @expectedException InvalidArgumentException - */ public function testInvalidWatchConnectivityState2() { + $this->expectException(InvalidArgumentException::class); $this->channel = new Grpc\Gcp\GcpExtensionChannel('localhost:50013', ['credentials' => Grpc\ChannelCredentials::createInsecure()]); $this->channel->watchConnectivityState(1, 'hi'); @@ -406,11 +392,9 @@ public function testPersistentChannelSharedChannelClose1() $this->assertEquals(GRPC\CHANNEL_IDLE, $state); } - /** - * @expectedException RuntimeException - */ public function testPersistentChannelSharedChannelClose2() { + $this->expectException(RuntimeException::class); // same underlying channel $this->channel1 = new Grpc\Gcp\GcpExtensionChannel('localhost:50223', [ "grpc_target_persist_bound" => 3, @@ -640,11 +624,9 @@ public function testPersistentChannelForceNewOldChannelClose1() $this->assertEquals(GRPC\CHANNEL_IDLE, $state); } - /** - * @expectedException RuntimeException - */ public function testPersistentChannelForceNewOldChannelClose2() { + $this->expectException(RuntimeException::class); $this->channel1 = new Grpc\Gcp\GcpExtensionChannel('localhost:50230', [ "grpc_target_persist_bound" => 2, ]);