Skip to content

Do not reuse Oracle connections for CI #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
ACCEPT_EULA: Y
SA_PASSWORD: atk4_pass
oracle:
image: wnameless/oracle-xe-11g-r2
image: ghcr.io/mvorisek/docker-oracle-xe-11g
env:
ORACLE_ALLOW_REMOTE: true
steps:
Expand Down
60 changes: 0 additions & 60 deletions src/Persistence/Sql/Oracle/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,66 +31,6 @@ protected static function createDbalEventManager(): EventManager
return $evm;
}

// {{{ fix for too many connections for CI testing

/** @var int */
private static $ciDifferentDsnCounter = 0;
/** @var array */
private static $ciLastConnectDsn;
/** @var \PDO|null */
private static $ciLastConnectPdo;

protected static function connectDbalConnection(array $dsn)
{
// for some reasons, the following error:
// PDOException: SQLSTATE[HY000]: pdo_oci_handle_factory: ORA-12516: TNS:listener could not find available handler with matching protocol stack
// is shown randomly when a lot of connections are created in tests,
// so for CI, fix this issue by reusing the previous PDO connection
// TODO remove once atk4/data tests can be run consistently without errors
if (class_exists(\PHPUnit\Framework\TestCase::class, false)) { // called from phpunit
$notReusableFunc = function (string $message): void {
echo "\n" . 'connection for CI cannot be reused:' . "\n" . $message . "\n";
self::$ciLastConnectPdo = null;
};

if (self::$ciLastConnectDsn !== $dsn) {
++self::$ciDifferentDsnCounter;
if (self::$ciDifferentDsnCounter >= 4) {
$notReusableFunc('different DSN');
}
} elseif (self::$ciLastConnectPdo !== null) {
try {
self::$ciLastConnectPdo->query('select 1 from dual')->fetch();
} catch (\PDOException $e) {
$notReusableFunc((string) $e);
}
}

if (self::$ciLastConnectPdo !== null && self::$ciLastConnectPdo->inTransaction()) {
$notReusableFunc('inside transaction');
}

if (self::$ciLastConnectPdo !== null) {
$dbalConnection = parent::connectDbalConnection(['pdo' => self::$ciLastConnectPdo]);
} else {
$dbalConnection = parent::connectDbalConnection($dsn);
}

if (BaseConnection::isComposerDbal2x()) {
self::$ciLastConnectPdo = $dbalConnection->getWrappedConnection(); // @phpstan-ignore-line
} else {
self::$ciLastConnectPdo = $dbalConnection->getWrappedConnection()->getWrappedConnection(); // @phpstan-ignore-line
}
self::$ciLastConnectDsn = $dsn;

return $dbalConnection;
}

return parent::connectDbalConnection($dsn);
}

/// }}}

/**
* Return last inserted ID value.
*
Expand Down