Skip to content

Commit 93d3108

Browse files
abnegateclaude
andcommitted
fix: replace slow waitForRedis polling with direct reconnect
Remove waitForRedis() which polled 60x with 500ms delay requiring 5 consecutive successes. Replace with sleep(2) + reconnectCache() which creates a fresh Redis connection. This reduces Redis-Destructive test time from ~18 minutes to ~10 seconds per adapter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 98a4fa8 commit 93d3108

1 file changed

Lines changed: 4 additions & 25 deletions

File tree

tests/e2e/Adapter/Scopes/GeneralTests.php

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public function testCacheFallback(): void
398398

399399
// Restart Redis containers
400400
Console::execute('docker ps -a --filter "name=utopia-redis" --format "{{.Names}}" | xargs -r docker start', '', $stdout, $stderr);
401-
$this->waitForRedis();
401+
sleep(2);
402402
$this->reconnectCache();
403403

404404
$this->assertCount(1, $database->find('testRedisFallback', [Query::equal('string', ['text📝'])]));
@@ -416,8 +416,7 @@ public function testCacheReconnect(): void
416416
return;
417417
}
418418

419-
// Wait for Redis to be fully healthy after previous test
420-
$this->waitForRedis();
419+
sleep(2);
421420
$this->reconnectCache();
422421

423422
$database->getAuthorization()->cleanRoles();
@@ -450,7 +449,7 @@ public function testCacheReconnect(): void
450449

451450
// Restart Redis containers
452451
Console::execute('docker ps -a --filter "name=utopia-redis" --format "{{.Names}}" | xargs -r docker start', '', $stdout, $stderr);
453-
$this->waitForRedis();
452+
sleep(2);
454453
$this->reconnectCache();
455454

456455
// Cache should reconnect - read should work
@@ -470,7 +469,7 @@ public function testCacheReconnect(): void
470469
$stdout = '';
471470
$stderr = '';
472471
Console::execute('docker ps -a --filter "name=utopia-redis" --filter "status=exited" --format "{{.Names}}" | xargs -r docker start', '', $stdout, $stderr);
473-
$this->waitForRedis();
472+
sleep(2);
474473
$this->reconnectCache();
475474

476475
// Cleanup collection if it exists
@@ -710,24 +709,4 @@ private function reconnectCache(): void
710709
$this->getDatabase()->setCache(new \Utopia\Cache\Cache($adapter));
711710
}
712711

713-
private function waitForRedis(int $maxRetries = 60, int $delayMs = 500): void
714-
{
715-
$consecutive = 0;
716-
$required = 5;
717-
for ($i = 0; $i < $maxRetries; $i++) {
718-
usleep($delayMs * 1000);
719-
try {
720-
$redis = new \Redis();
721-
$redis->connect('redis', 6379, 1.0);
722-
$redis->ping();
723-
$redis->close();
724-
$consecutive++;
725-
if ($consecutive >= $required) {
726-
return;
727-
}
728-
} catch (\RedisException $e) {
729-
$consecutive = 0;
730-
}
731-
}
732-
}
733712
}

0 commit comments

Comments
 (0)