Merge pull request #12559 from appwrite/fix-locktest-connections-cache

Fix lock unit test Redis connection
This commit is contained in:
premtsd-code authored and GitHub committed 2026-06-10 14:17:12 +01:00
commit c54c984beb
1 file changed
+23 -2
+23 -2
View File
@@ -11,6 +11,7 @@ use Redis;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Validator\Authorization;
use Utopia\DSN\DSN;
use Utopia\Logger\Log;
use Utopia\Telemetry\Adapter\None as NoTelemetry;
@@ -34,8 +35,7 @@ final class LockTest extends TestCase
protected function setUp(): void
{
$host = \getenv('_APP_REDIS_HOST') ?: 'redis';
$port = (int) (\getenv('_APP_REDIS_PORT') ?: 6379);
[$host, $port] = $this->getRedisConnection();
$this->redis = new Redis();
$this->redis->connect($host, $port, 1.0);
@@ -50,6 +50,27 @@ final class LockTest extends TestCase
$this->cleanupKeys();
}
/**
* @return array{0: string, 1: int}
*/
private function getRedisConnection(): array
{
$dsn = \getenv('_APP_CONNECTIONS_CACHE') ?: '';
if ($dsn !== '') {
$dsn = \explode(',', $dsn, 2)[0];
$dsn = \explode('=', $dsn, 2)[1] ?? $dsn;
$parsed = new DSN($dsn);
return [$parsed->getHost(), (int) ($parsed->getPort() ?? '6379')];
}
return [
\getenv('_APP_REDIS_HOST') ?: 'redis',
(int) (\getenv('_APP_REDIS_PORT') ?: 6379),
];
}
protected function tearDown(): void
{
if (isset($this->redis) && $this->redis->isConnected()) {