Skip to content

Commit

Permalink
Redis ee testing (#18)
Browse files Browse the repository at this point in the history
* Added Redis EE tests workflow

* Changed directory

* Added skip for tests on enterprise env

* Fix broken tests

* More skipped tests added

* Added OSS Cluster job

* Changed cluster DB PORT value

* Updated exported files

* Fixed codestyle typo

* Updated README.md

* Changed repository URL

* Changed ENV variables names to corresponding one

* Changed image to existing one

* Changed image name
  • Loading branch information
vladvildanov authored Jan 11, 2024
1 parent 6652259 commit e237d1c
Show file tree
Hide file tree
Showing 68 changed files with 429 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:

- name: Check exported files
run: |
EXPECTED="LICENSE,README.md,autoload.php,composer.json"
EXPECTED="LICENSE,README.md,autoload.php,composer.json,phpunit.enterprise.xml"
CURRENT="$(
git archive HEAD \
| tar --list --exclude="src" --exclude="src/*" --exclude="bin" --exclude="bin/*" --exclude="docker" --exclude="docker/*" \
Expand Down
103 changes: 103 additions & 0 deletions .github/workflows/tests-enterprise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Tests Enterprise

on:
push:
branches:
- main
- v2.**
- v3.**
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

predis-enterprise:
name: PHP 8.0 (Redis EE)
runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- name: Clone Redis EE docker repository
run: |
git clone https://github.com/RedisLabs/redis-ee-docker.git redis-ee
- name: Build cluster
env:
IMAGE: redislabs/redis-internal:100.0.1-64956
RE_USERNAME: test@test.com
RE_PASS: 12345
RE_CLUSTER_NAME: test
RE_USE_OSS_CLUSTER: false
RE_DB_PORT: 6379
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
cd redis-ee/
./build.sh
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup PHP with Composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: relay, apcu
ini-values: apc.enable_cli=1

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: highest

- name: Run tests
run: vendor/bin/phpunit -c phpunit.enterprise.xml

predis-enterprise-oss-cluster:
name: PHP 8.0 (Redis EE OSS Cluster)
runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- name: Clone Redis EE docker repository
run: |
git clone https://github.com/RedisLabs/redis-ee-docker.git redis-ee
- name: Build cluster
env:
IMAGE: redislabs/redis-internal:100.0.1-64956
RE_USERNAME: test@test.com
RE_PASS: 12345
RE_CLUSTER_NAME: test
RE_USE_OSS_CLUSTER: true
RE_DB_PORT: 6378
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
cd redis-ee/
./build.sh
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup PHP with Composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: relay, apcu
ini-values: apc.enable_cli=1

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: highest

- name: Run tests
run: vendor/bin/phpunit -c phpunit.enterprise.xml --group cluster
2 changes: 1 addition & 1 deletion examples/client_side_caching_mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

// 1. Create client with enabled cache and RESP3 connection mode.
$client = new \Predis\Client(['cache' => true]);
$client = new Predis\Client(['cache' => true]);
$client->flushall();

// 2. Set key into Redis storage.
Expand Down
2 changes: 1 addition & 1 deletion examples/dispatcher_loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$pubsub = $client->pubSubLoop();

// Create a dispatcher loop instance and attach a bunch of callbacks.
$dispatcher = new \Predis\Consumer\PubSub\DispatcherLoop($pubsub);
$dispatcher = new Predis\Consumer\PubSub\DispatcherLoop($pubsub);

// Demonstrate how to use a callable class as a callback for the dispatcher loop.
class EventsListener implements Countable
Expand Down
2 changes: 1 addition & 1 deletion examples/sharded_dispatcher_loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
$pubSub = $client->pubSubLoop();

// 3. Create a dispatcher loop instance and attach a bunch of callbacks.
$dispatcher = new \Predis\Consumer\PubSub\DispatcherLoop($pubSub);
$dispatcher = new Predis\Consumer\PubSub\DispatcherLoop($pubSub);

// 4. Demonstrate how to use a callable class as a callback for the dispatcher loop.
class EventsListener implements Countable
Expand Down
33 changes: 33 additions & 0 deletions examples/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

require __DIR__ . '/shared.php';
require __DIR__ . '/../vendor/autoload.php';

use Predis\Client;

$client = new Client(
[
'tcp://127.0.0.1:26379?username=default&password=password',
'tcp://127.0.0.1:26380?username=default&password=password',
'tcp://127.0.0.1:26381?username=default&password=password',
], [
'replication' => 'sentinel',
'service' => 'mymaster',
'parameters' => [
'username' => 'default',
'password' => 'password',
],
]);

$client->set('key', 'value');
var_dump($client->get('key'));
60 changes: 60 additions & 0 deletions phpunit.enterprise.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
beStrictAboutTestsThatDoNotTestAnything="true"
>

<testsuites>
<testsuite name="Enterprise Test Suite">
<directory>tests/Predis/</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>

<groups>
<exclude>
<group>ext-relay</group>
<group>ext-curl</group>
<group>cluster</group>
<group>gears</group>
<group>gears-cluster</group>
<!-- <group>connected</group> -->
<!-- <group>disconnected</group> -->
<!-- <group>commands</group> -->
<!-- <group>slow</group> -->
</exclude>
</groups>

<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<php>
<const name="REDIS_SERVER_HOST" value="127.0.0.1" />
<const name="REDIS_SERVER_PORT" value="6379" />
<const name="REDIS_SERVER_DBNUM" value="0" />
<env name="USE_RELAY" value="false" />
<env name="REDIS_ENTERPRISE" value="1" />

<!-- Redis Cluster -->
<!-- Only master nodes endpoints included -->
<const name="REDIS_CLUSTER_ENDPOINTS" value="127.0.0.1:6372,127.0.0.1:6373,127.0.0.1:6374" />
</php>
</phpunit>
6 changes: 3 additions & 3 deletions src/Connection/RelayConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RelayConnection extends StreamConnection
/**
* The Relay instance.
*
* @var \Relay\Relay
* @var Relay
*/
protected $client;

Expand Down Expand Up @@ -150,7 +150,7 @@ protected function assertParameters(ParametersInterface $parameters)
/**
* Creates a new instance of the client.
*
* @return \Relay\Relay
* @return Relay
*/
private function createClient()
{
Expand Down Expand Up @@ -188,7 +188,7 @@ private function createClient()
/**
* Returns the underlying client.
*
* @return \Relay\Relay
* @return Relay
*/
public function getClient()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Pipeline/RelayPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RelayPipeline extends Pipeline
*/
protected function executePipeline(ConnectionInterface $connection, SplQueue $commands)
{
/** @var \Predis\Connection\RelayConnection $connection */
/** @var RelayConnection $connection */
$client = $connection->getClient();

$throw = $this->client->getOptions()->exceptions;
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPUnit/ArrayHasSameValuesConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* PHPUnit constraint matching arrays with same elements even in different order.
*/
class ArrayHasSameValuesConstraint extends \PHPUnit\Framework\Constraint\Constraint
class ArrayHasSameValuesConstraint extends PHPUnit\Framework\Constraint\Constraint
{
protected $array;

Expand Down
27 changes: 23 additions & 4 deletions tests/PHPUnit/PredisTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Base test case class for the Predis test suite.
*/
abstract class PredisTestCase extends \PHPUnit\Framework\TestCase
abstract class PredisTestCase extends PHPUnit\Framework\TestCase
{
protected $redisServerVersion;
protected $redisJsonVersion;
Expand Down Expand Up @@ -54,6 +54,8 @@ protected function setUp(): void
foreach ($this->modulesMapping as $module => $config) {
$this->checkRequiredRedisModuleVersion($module);
}

$this->markTestSkippedOnEnterpriseEnvironment();
}

/**
Expand Down Expand Up @@ -151,7 +153,7 @@ public function assertSameWithPrecision($expected, $actual, int $precision = 0,
* Asserts that a string matches a given regular expression.
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertMatchesRegularExpression(string $pattern, string $string, $message = ''): void
{
Expand Down Expand Up @@ -296,7 +298,7 @@ protected function getMockConnectionOfType(string $interface, $parameters = null
if (!is_a($interface, '\Predis\Connection\NodeConnectionInterface', true)) {
$method = __METHOD__;

throw new \InvalidArgumentException(
throw new InvalidArgumentException(
"Argument `\$interface` for $method() expects a type implementing Predis\Connection\NodeConnectionInterface"
);
}
Expand Down Expand Up @@ -424,7 +426,7 @@ public function isRedisServerVersion(string $operator, string $version): bool
* decorates test methods while the version of the Redis server used to run
* integration tests is retrieved directly from the server by using `INFO`.
*
* @throws \PHPUnit\Framework\SkippedTestError When the required Redis server version is not met
* @throws PHPUnit\Framework\SkippedTestError When the required Redis server version is not met
*/
protected function checkRequiredRedisServerVersion(): void
{
Expand Down Expand Up @@ -561,6 +563,23 @@ protected function markTestSkippedOnCIEnvironment(string $message = 'Test skippe
}
}

/**
* Marks current test skipped in Redis Enterprise environment.
*/
protected function markTestSkippedOnEnterpriseEnvironment(): void
{
$annotations = TestUtil::parseTestMethodAnnotations(
get_class($this),
$this->getName(false)
);

$annotationExists = isset($annotations['method']['skipEnterprise']);

if ($annotationExists && getenv('REDIS_ENTERPRISE')) {
$this->markTestSkipped('Test skipped on Redis Enterprise environment.');
}
}

/**
* Check annotations if it's matches to cluster test scenario.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPUnit/RedisCommandConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* PHPUnit constraint to verify that a Redis command matches certain conditions.
*/
class RedisCommandConstraint extends \PHPUnit\Framework\Constraint\Constraint
class RedisCommandConstraint extends PHPUnit\Framework\Constraint\Constraint
{
protected $commandID;
protected $arguments;
Expand Down
9 changes: 5 additions & 4 deletions tests/Predis/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ public function testGetClientByMethodSupportsSelectingConnectionByRole(): void
*/
public function testGetClientByMethodSupportsSelectingConnectionByCommand(): void
{
$command = \Predis\Command\RawCommand::create('GET', 'key');
$command = Command\RawCommand::create('GET', 'key');
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();

$aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')
Expand Down Expand Up @@ -1286,7 +1286,7 @@ public function testGetIteratorWithTraversableConnections(): void
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382');
$connection3 = $this->getMockConnection('tcp://127.0.0.1:6383');

$aggregate = new \Predis\Connection\Cluster\PredisCluster(new Parameters());
$aggregate = new Connection\Cluster\PredisCluster(new Parameters());

$aggregate->add($connection1);
$aggregate->add($connection2);
Expand Down Expand Up @@ -1334,15 +1334,16 @@ public function testGetIteratorWithNonTraversableConnectionNoException(): void
* @group connected
* @group relay-incompatible
* @requiresRedisVersion >= 7.2.0
* @skipEnterprise
*/
public function testSetClientInfoOnConnection(): void
{
$client = new Client($this->getParameters());
$libName = $client->client('LIST')[0]['lib-name'];
$libVer = $client->client('LIST')[0]['lib-ver'];

$this->assertSame('predis', $libName);
$this->assertSame(Client::VERSION, $libVer);
$this->assertEquals('predis', $libName);
$this->assertEquals(Client::VERSION, $libVer);
}

/**
Expand Down
Loading

0 comments on commit e237d1c

Please sign in to comment.