Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@
'persistent_id' => 'summit_api_cache',
],

'doctrine_cache' => [
Comment thread
coderabbitai[bot] marked this conversation as resolved.
'host' => env('REDIS_HOST'),
'port' => env('REDIS_PORT'),
'database' => env('REDIS_DOCTRINE_CACHE_DB', 5),
'password' => env('REDIS_PASSWORD'),
'scheme' => env('REDIS_SCHEME', 'tcp'),
'read_write_timeout' => env('REDIS_READ_WRITE_TIMEOUT', 5),
'timeout' => env('REDIS_TIMEOUT', 5),
'persistent' => env('REDIS_PERSISTENT', false) ? 'summit_api_doctrine_cache' : false,
'persistent_id' => 'summit_api_doctrine_cache',
],

'session' => [
'host' => env('REDIS_HOST'),
'port' => env('REDIS_PORT'),
Expand Down
89 changes: 89 additions & 0 deletions tests/Unit/Services/DoctrineResultCacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php namespace Tests\Unit\Services;
/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\Models\Foundation\Main\IGroup;
use models\summit\SummitAttendee;
use Tests\InsertMemberTestData;
use Tests\InsertSummitTestData;
use Tests\TestCase;

/**
* Class DoctrineResultCacheTest
* The result cache of the model entity manager goes to the doctrine_redis store, whose connection
* (doctrine_cache) must exist: Symfony's cache adapter swallows the "connection not configured"
* exception, so a missing connection shows up only as a cache that never stores anything.
*/
class DoctrineResultCacheTest extends TestCase
{
use InsertSummitTestData;
use InsertMemberTestData;

protected function setUp(): void
{
parent::setUp();
self::insertMemberTestData(IGroup::TrackChairs);
self::$defaultMember = self::$member;
self::insertSummitTestData();
}

public function tearDown(): void
{
self::clearSummitTestData();
self::clearMemberTestData();
parent::tearDown();
}

private function resultCache()
{
return self::$em->getConfiguration()->getResultCache();
}

private function badgeFeaturesKey(int $attendee_id): string
{
return sprintf("ATTENDEES_%s_BADGE_FEATURES", $attendee_id);
}

public function testResultCacheSavesAndServesAnItem()
{
$cache = $this->resultCache();
$key = 'result-cache-test';
$cache->deleteItem($key);

$item = $cache->getItem($key);
$this->assertFalse($item->isHit());
$item->set('value')->expiresAfter(60);
$this->assertTrue($cache->save($item), 'the result cache must be able to store an item');

$this->assertTrue($cache->getItem($key)->isHit());
$this->assertSame('value', $cache->getItem($key)->get());

$cache->deleteItem($key);
$this->assertFalse($cache->getItem($key)->isHit());
}

public function testAllowedBadgeFeaturesAreCachedAndEvicted()
{
$attendee_id = self::$summit->getAttendees()[0]->getId();
$attendee = self::$em->find(SummitAttendee::class, $attendee_id);
$cache = $this->resultCache();
$key = $this->badgeFeaturesKey($attendee_id);
$cache->deleteItem($key);

$attendee->getAllowedBadgeFeatures();
$this->assertTrue($cache->getItem($key)->isHit(), 'getAllowedBadgeFeatures must leave its entry in the result cache');

$attendee->evictAllowedBadgeFeaturesCache();
$this->assertFalse($cache->getItem($key)->isHit(), 'evictAllowedBadgeFeaturesCache must remove the entry');
}
}
6 changes: 3 additions & 3 deletions tests/Unit/Services/RedisPersistentConnectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function redisConfigWith(?string $persistent): array
public function testPersistentConnectionsAreOffByDefault()
{
$redis = $this->redisConfigWith(null);
foreach (['default', 'cache', 'session', 'worker'] as $name) {
foreach (['default', 'cache', 'doctrine_cache', 'session', 'worker'] as $name) {
$this->assertFalse($redis[$name]['persistent'], "$name must not be persistent by default");
}
}
Expand All @@ -54,12 +54,12 @@ public function testEveryConnectionGetsItsOwnPersistentId()
// connections share host:port: a shared socket would let one connection's SELECT switch the database of another
$redis = $this->redisConfigWith('true');
$ids = [];
foreach (['default', 'cache', 'session', 'worker'] as $name) {
foreach (['default', 'cache', 'doctrine_cache', 'session', 'worker'] as $name) {
$this->assertNotEmpty($redis[$name]['persistent'], "$name must be persistent");
$this->assertSame($redis[$name]['persistent'], $redis[$name]['persistent_id'], "predis and phpredis must use the same id for $name");
$ids[] = $redis[$name]['persistent_id'];
}
$this->assertCount(4, array_unique($ids));
$this->assertCount(5, array_unique($ids));
}

/**
Expand Down
Loading