Skip to content

Commit 2b1cde7

Browse files
committed
test: add redis cluster tests
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent cd99d14 commit 2b1cde7

4 files changed

Lines changed: 154 additions & 8 deletions

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
name: PHPUnit Redis
5+
6+
on:
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: phpunit-redis-${{ github.head_ref || github.run_id }}
14+
cancel-in-progress: true
15+
16+
env:
17+
REDIS_IMAGE: redis:8
18+
19+
jobs:
20+
changes:
21+
runs-on: ubuntu-latest-low
22+
23+
outputs:
24+
src: ${{ steps.changes.outputs.src}}
25+
26+
steps:
27+
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
28+
id: changes
29+
continue-on-error: true
30+
with:
31+
filters: |
32+
src:
33+
- '.github/workflows/phpunit-redis.yml'
34+
- '3rdparty/**'
35+
- '**/appinfo/**'
36+
- '**.php'
37+
38+
phpunit-redis:
39+
runs-on: ubuntu-latest
40+
41+
needs: changes
42+
if: needs.changes.outputs.src != 'false'
43+
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
php-versions: ["8.3", "8.5"]
48+
# The two supported topologies for the Redis cache
49+
topology: ["single", "cluster"]
50+
include:
51+
- topology: single
52+
config-file: redis.config.php
53+
- topology: cluster
54+
config-file: redis-cluster.config.php
55+
56+
name: Redis ${{ matrix.topology }} (PHP ${{ matrix.php-versions }})
57+
58+
steps:
59+
- name: Checkout server
60+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
61+
with:
62+
persist-credentials: false
63+
submodules: true
64+
65+
- name: Set up php ${{ matrix.php-versions }}
66+
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 #v2.37.2
67+
timeout-minutes: 5
68+
with:
69+
php-version: ${{ matrix.php-versions }}
70+
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
71+
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, pdo_sqlite, posix, redis, session, simplexml, sqlite, xmlreader, xmlwriter, zip, zlib
72+
coverage: none
73+
ini-file: development
74+
ini-values: disable_functions=""
75+
env:
76+
fail-fast: true
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Start Redis (single server)
80+
if: matrix.topology == 'single'
81+
run: |
82+
docker run -d --name redis-single -p 6379:6379 "${REDIS_IMAGE}"
83+
timeout 60 sh -c 'until docker exec redis-single redis-cli ping | grep -q PONG; do sleep 1; done'
84+
85+
- name: Start Redis (cluster)
86+
if: matrix.topology == 'cluster'
87+
run: |
88+
for port in 7000 7001 7002 7003 7004 7005; do
89+
docker run -d --name "redis-cluster-$port" --network host "${REDIS_IMAGE}" \
90+
redis-server --port "$port" --cluster-enabled yes \
91+
--cluster-config-file "nodes-$port.conf" --cluster-node-timeout 5000 \
92+
--appendonly no --save ""
93+
done
94+
# Wait for every node to answer before forming the cluster
95+
for port in 7000 7001 7002 7003 7004 7005; do
96+
timeout 60 sh -c "until docker exec redis-cluster-$port redis-cli -p $port ping | grep -q PONG; do sleep 1; done"
97+
done
98+
docker exec redis-cluster-7000 redis-cli --cluster create \
99+
127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 \
100+
127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 \
101+
--cluster-replicas 1 --cluster-yes
102+
103+
- name: Set up dependencies
104+
run: composer i
105+
106+
- name: Set up Nextcloud
107+
run: |
108+
mkdir data
109+
cp tests/${{ matrix.config-file }} config/
110+
cp tests/preseed-config.php config/config.php
111+
./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
112+
php -f tests/enable_all.php
113+
114+
- name: PHPUnit Redis tests
115+
run: composer run test -- --group Redis --log-junit junit.xml
116+
117+
- name: Print logs
118+
if: always()
119+
run: |
120+
cat data/nextcloud.log
121+
122+
summary:
123+
permissions:
124+
contents: none
125+
runs-on: ubuntu-latest-low
126+
needs: [changes, phpunit-redis]
127+
128+
if: always()
129+
130+
name: phpunit-redis-summary
131+
132+
steps:
133+
- name: Summary status
134+
run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-redis.result != 'success' }}; then exit 1; fi

tests/lib/Memcache/Cache.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
namespace Test\Memcache;
1010

11+
use OC\Memcache\Cache as MemcacheCache;
1112
use OCP\IMemcache;
1213

1314
abstract class Cache extends \Test\Cache\TestCache {
1415
/**
15-
* @var IMemcache cache;
16+
* @var IMemcache&MemcacheCache cache;
1617
*/
1718
protected $instance;
1819

@@ -147,6 +148,16 @@ public function testNcadNotSet(): void {
147148
$this->assertFalse($this->instance->ncad('foo', 'bar'));
148149
}
149150

151+
public function testClearWorks(): void {
152+
$this->instance->set('foo', 'bar');
153+
$this->instance->set('foo2', 'bar2');
154+
$this->instance->set('fbar', 'stays');
155+
self::assertTrue($this->instance->clear('fo'));
156+
self::assertNull($this->instance->get('foo'));
157+
self::assertNull($this->instance->get('foo2'));
158+
self::assertEquals('stays', $this->instance->get('fbar'));
159+
}
160+
150161
#[\Override]
151162
protected function tearDown(): void {
152163
if ($this->instance) {

tests/lib/Memcache/RedisTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public static function setUpBeforeClass(): void {
2828
self::markTestSkipped('The redis extension is not available.');
2929
}
3030

31-
if (Server::get(IConfig::class)->getSystemValue('redis', []) === []) {
31+
$config = Server::get(IConfig::class);
32+
if ($config->getSystemValue('redis', []) === [] && $config->getSystemValue('redis.cluster', []) === []) {
3233
self::markTestSkipped('Redis not configured in config.php');
3334
}
3435

tests/redis-cluster.config.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
'memcache.locking' => '\\OC\\Memcache\\Redis',
1313
'redis.cluster' => [
1414
'seeds' => [ // provide some/all of the cluster servers to bootstrap discovery, port required
15-
'cache-cluster:7000',
16-
'cache-cluster:7001',
17-
'cache-cluster:7002',
18-
'cache-cluster:7003',
19-
'cache-cluster:7004',
20-
'cache-cluster:7005'
15+
'localhost:7000',
16+
'localhost:7001',
17+
'localhost:7002',
18+
'localhost:7003',
19+
'localhost:7004',
20+
'localhost:7005'
2121
],
2222
'timeout' => 0.0,
2323
'read_timeout' => 0.0,

0 commit comments

Comments
 (0)