Skip to content

Commit

Permalink
chore: add testing CI, fix tests (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Apr 24, 2023
1 parent 6f91c8c commit 4d8b455
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 93 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .github/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
releaseType: simple
handleGHRelease: true
primaryBranch: main
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 0 additions & 2 deletions grpc-gcp-bootstrap.php

This file was deleted.

5 changes: 2 additions & 3 deletions phpunit-grpc-gcp.xml.dist → phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="./grpc-gcp-bootstrap.php"
colors="true">
<testsuites>
<testsuite>
<directory>./tests/grpc-gcp</directory>
<testsuite name="grpc-gcp-tests">
<directory>./tests/grpc-gcp/grpc_unit_test</directory>
</testsuite>
</testsuites>
<filter>
Expand Down
29 changes: 10 additions & 19 deletions tests/grpc-gcp/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
29 changes: 10 additions & 19 deletions tests/grpc-gcp/ChannelManagementNoConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 8 additions & 13 deletions tests/grpc-gcp/ReproduceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 4d8b455

Please sign in to comment.