Skip to content

Commit

Permalink
retry only for getDbConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
zajca committed Feb 7, 2025
1 parent b475bef commit 1dbaae9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions tests/Backend/WorkspaceConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait WorkspaceConnectionTrait
/**
* @return SnowflakeConnection|DBALConnection|\PDO|BigQueryClient
*/
private function getDbConnection(array $connection)
private function getDbConnection(array $connection, int $retriesCount = 20)
{
switch ($connection['backend']) {
case StorageApiTestCase::BACKEND_SNOWFLAKE:
Expand All @@ -35,7 +35,7 @@ private function getDbConnection(array $connection)
case StorageApiTestCase::BACKEND_TERADATA:
return $this->getDbConnectionTeradata($connection);
case StorageApiTestCase::BACKEND_BIGQUERY:
return $this->getDbConnectionBigquery($connection);
return $this->getDbConnectionBigquery($connection, $retriesCount);
}

throw new \Exception('Unsupported Backend for workspaces');
Expand Down Expand Up @@ -148,14 +148,14 @@ private function getDbConnectionTeradata(array $connection): DBALConnection
return $db;
}

private function getDbConnectionBigquery(array $connection): BigQueryClient
private function getDbConnectionBigquery(array $connection, int $retriesCount): BigQueryClient
{
// note: the close method is not used in this client
$bqClient = new BigQueryClientWrapper([
'keyFile' => $connection['credentials'],
'restRetryFunction' => Retry::getRestRetryFunction(new NullLogger()),
'requestTimeout' => 120,
'retries' => 10,
'retries' => $retriesCount,
], 'sapitest');

$bqClient->runQuery(
Expand Down
2 changes: 1 addition & 1 deletion tests/Backend/WorkspaceCredentialsAssertTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private function assertCredentialsShouldNotWork($connection): void
try {
$proxy = new RetryProxy($retryPolicy, new ExponentialBackOffPolicy());
$proxy->call(function () use ($connection) {
$this->getDbConnection($connection);
$this->getDbConnection($connection, 1);
throw new \Exception(self::$RETRY_FAIL_MESSAGE);
});
} catch (\Doctrine\DBAL\Driver\Exception $e) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Backend/Workspaces/Backend/BigqueryWorkspaceBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class BigqueryWorkspaceBackend implements WorkspaceBackend
/**
* @param array $workspace
*/
public function __construct(array $workspace, int $retriesCount)
public function __construct(array $workspace)
{
$bqClient = new BigQueryClientWrapper([
'keyFile' => $workspace['connection']['credentials'],
'restRetryFunction' => Retry::getRestRetryFunction(new NullLogger()),
'requestTimeout' => 120,
'retries' => $retriesCount,
'retries' => 20,
], 'sapitest');

$this->bqClient = $bqClient;
Expand Down
4 changes: 2 additions & 2 deletions tests/Backend/Workspaces/Backend/WorkspaceBackendFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WorkspaceBackendFactory
/**
* @param array<mixed> $workspace
*/
public static function createWorkspaceBackend(array $workspace, bool $useDBAL = false, int $retriesCount = 10): WorkspaceBackend
public static function createWorkspaceBackend(array $workspace, bool $useDBAL = false): WorkspaceBackend
{
switch ($workspace['connection']['backend']) {
case StorageApiTestCase::BACKEND_REDSHIFT:
Expand All @@ -33,7 +33,7 @@ public static function createWorkspaceBackend(array $workspace, bool $useDBAL =
case StorageApiTestCase::BACKEND_TERADATA:
return new TeradataWorkspaceBackend($workspace);
case StorageApiTestCase::BACKEND_BIGQUERY:
return new BigqueryWorkspaceBackend($workspace, $retriesCount);
return new BigqueryWorkspaceBackend($workspace);
default:
throw new Exception($workspace['connection']['backend'] . ' workspaces are not supported.');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Backend/Workspaces/WorkspacesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function testWorkspaceCreate(bool $async): void
$tokenInfo = $this->_client->verifyToken();
$this->assertEquals($tokenInfo['owner']['defaultBackend'], $connection['backend']);

$backend = WorkspaceBackendFactory::createWorkspaceBackend($workspace, false, 2);
$backend = WorkspaceBackendFactory::createWorkspaceBackend($workspace);

if ($workspaceWithSnowflakeBackend) {
$db = $backend->getDb();
Expand Down Expand Up @@ -254,7 +254,7 @@ public function testWorkspacePasswordReset(): void
$tokenInfo = $this->_client->verifyToken();
$this->assertEquals($tokenInfo['owner']['defaultBackend'], $connection['backend']);

$backend = WorkspaceBackendFactory::createWorkspaceBackend($workspace, false, 2);
$backend = WorkspaceBackendFactory::createWorkspaceBackend($workspace);
$backend->dropTableIfExists('mytable');

$backend->createTable('mytable', ['amount' => $this->getColumnAmountType($connection['backend'])]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Common/BranchWorkspacesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testWorkspaceCreate(bool $async): void
$tokenInfo = $this->_client->verifyToken();
$this->assertEquals($tokenInfo['owner']['defaultBackend'], $connection['backend']);

$backend = WorkspaceBackendFactory::createWorkspaceBackend($workspace, false, 2);
$backend = WorkspaceBackendFactory::createWorkspaceBackend($workspace);
$backend->createTable('mytable', ['amount' => ($connection['backend'] === self::BACKEND_SNOWFLAKE) ? 'NUMBER' : 'VARCHAR']);

$tableNames = $backend->getTables();
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testWorkspacePasswordReset(): void
$tokenInfo = $this->_client->verifyToken();
$this->assertEquals($tokenInfo['owner']['defaultBackend'], $connection['backend']);

$backend = WorkspaceBackendFactory::createWorkspaceBackend($workspace, false, 2);
$backend = WorkspaceBackendFactory::createWorkspaceBackend($workspace);
$backend->dropTableIfExists('mytable');
$backend->createTable('mytable', ['amount' => ($connection['backend'] === self::BACKEND_SNOWFLAKE) ? 'NUMBER' : 'VARCHAR']);

Expand Down

0 comments on commit 1dbaae9

Please sign in to comment.