8000 Update tests so they can run in php-cgi. by michael-grunder · Pull Request #2508 · phpredis/phpredis · GitHub
[go: up one dir, main page]

Skip to content

Update tests so they can run in php-cgi. #2508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2024
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
3 changes: 2 additions & 1 deletion tests/RedisArrayTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n");
require_once(dirname($_SERVER['PHP_SELF'])."/TestSuite.php");

require_once __DIR__ . "/TestSuite.php";

define('REDIS_ARRAY_DATA_SIZE', 1000);
define('REDIS_RA_DEFAULT_PORTS', [6379, 6380, 6381, 6382]);
Expand Down
13 changes: 7 additions & 6 deletions tests/RedisClusterTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n");
require_once(dirname($_SERVER['PHP_SELF'])."/RedisTest.php");

require_once __DIR__ . "/RedisTest.php";

/**
* Most RedisCluster tests should work the same as the standard Redis object
Expand Down Expand Up @@ -111,9 +112,9 @@ private function loadSeeds($host, $port) {
if (($seeds = $this->loadSeedsFromHostPort($host, $port)))
return $seeds;

fprintf(STDERR, "Error: Unable to load seeds for RedisCluster tests\n");
TestSuite::errorMessage("Error: Unable to load seeds for RedisCluster tests");
foreach (self::$seed_messages as $msg) {
fprintf(STDERR, " Tried: %s\n", $msg);
TestSuite::errorMessage(" Tried: %s", $msg);
}

exit(1);
Expand All @@ -139,9 +140,9 @@ protected function newInstance() {
try {
return new RedisCluster(NULL, self::$seeds, 30, 30, true, $this->getAuth());
} catch (Exception $ex) {
fprintf(STDERR, "Fatal error: %s\n", $ex->getMessage());
fprintf(STDERR, "Seeds: %s\n", implode(' ', self::$seeds));
fprintf(STDERR, "Seed source: %s\n", self::$seed_source);
TestSuite::errorMessage("Fatal error: %s\n", $ex->getMessage());
TestSuite::errorMessage("Seeds: %s\n", implode(' ', self::$seeds));
TestSuite::errorMessage("Seed source: %s\n", self::$seed_source);
exit(1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/RedisSentinelTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php defined('PHPREDIS_TESTRUN') or die("Use TestRedis.php to run tests!\n");

require_once(dirname($_SERVER['PHP_SELF'])."/TestSuite.php");
require_once __DIR__ . "/TestSuite.php";

class Redis_Sentinel_Test extends TestSuite
{
Expand Down
43 changes: 41 additions & 2 deletions tests/RedisTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php defined('PHPREDIS_TESTRUN') or die('Use TestRedis.php to run tests!\n');

require_once(dirname($_SERVER['PHP_SELF']).'/TestSuite.php');
require_once(dirname($_SERVER['PHP_SELF']).'/SessionHelpers.php');
require_once __DIR__ . '/TestSuite.php';
require_once __DIR__ . '/SessionHelpers.php';

class Redis_Test extends TestSuite {
/**
Expand Down Expand Up @@ -7223,7 +7223,15 @@ protected function sessionRunner() {
->savePath($this->sessionSavePath());
}

protected function testRequiresMode(string $mode) {
if (php_sapi_name() != $mode) {
$this->markTestSkipped("Test requires PHP running in '$mode' mode");
}
}

public function testSession_compression() {
$this->testRequiresMode('cli');

foreach ($this->getCompressors() as $name => $val) {
$data = "testing_compression_$name";

Expand All @@ -7244,6 +7252,8 @@ public function testSession_compression() {
}

public function testSession_savedToRedis() {
$this->testRequiresMode('cli');

$runner = $this->sessionRunner();

$this->assertEquals('SUCCESS', $runner->execFg());
Expand All @@ -7260,6 +7270,8 @@ protected function sessionWaitSec() {
}

public function testSession_lockKeyCorrect() {
$this->testRequiresMode('cli');

$runner = $this->sessionRunner()->sleep(5);

$this->assertTrue($runner->execBg());
Expand All @@ -7272,6 +7284,8 @@ public function testSession_lockKeyCorrect() {
}
public function testSession_lockingDisabledByDefault() {
$this->testRequiresMode('cli');

$runner = $this->sessionRunner()
->lockingEnabled(false)
->sleep(5);
Expand All @@ -7281,6 +7295,8 @@ public function testSession_lockingDisabledByDefault() {
}

public function testSession_lockReleasedOnClose() {
$this->testRequiresMode('cli');

$runner = $this->sessionRunner()
->sleep(1)
->lockingEnabled(true);
Expand All @@ -7291,6 +7307,8 @@ public function testSession_lockReleasedOnClose() {
}

public function testSession_lock_ttlMaxExecutionTime() {
$this->testRequiresMode('cli');

$runner1 = $this->sessionRunner()
->sleep(10)
->maxExecutionTime(2);
Expand All @@ -7309,6 +7327,7 @@ public function testSession_lock_ttlMaxExecutionTime() {
}

public function testSession_lock_ttlLockExpire() {
$this->testRequiresMode('cli');

$runner1 = $this->sessionRunner()
->sleep(10)
Expand All @@ -7329,6 +7348,8 @@ public function testSession_lock_ttlLockExpire() {
}

public function testSession_lockHoldCheckBeforeWrite_otherProcessHasLock() {
$this->testRequiresMode('cli');

$id = 'test-id';

$runner = $this->sessionRunner()
Expand All @@ -7352,6 +7373,8 @@ public function testSession_lockHoldCheckBeforeWrite_otherProcessHasLock() {
}

public function testSession_lockHoldCheckBeforeWrite_nobodyHasLock() {
$this->testRequiresMode('cli');

$runner = $this->sessionRunner()
->sleep(2)
->lockingEnabled(true)
Expand All @@ -7363,6 +7386,8 @@ public function testSession_lockHoldCheckBeforeWrite_nobodyHasLock() {
}

public function testSession_correctLockRetryCount() {
$this->testRequiresMode('cli');

$runner = $this->sessionRunner()
->sleep(10);

Expand Down Expand Up @@ -7394,6 +7419,8 @@ public function testSession_correctLockRetryCount() {
}

public function testSession_defaultLockRetryCount() {
$this->testRequiresMode('cli');

$runner = $this->sessionRunner()
->sleep(10);

Expand All @@ -7420,6 +7447,8 @@ public function testSession_defaultLockRetryCount() {
}

public function testSession_noUnlockOfOtherProcess() {
$this->testRequiresMode('cli');

$st = microtime(true);

$sleep = 3;
Expand Down Expand Up @@ -7453,6 +7482,8 @@ public function testSession_noUnlockOfOtherProcess() {
}

public function testSession_lockWaitTime() {
$this->testRequiresMode('cli');


$runner = $this->sessionRunner()
->sleep(1)
Expand Down Expand Up @@ -7603,6 +7634,8 @@ public function testBadOptionValue() {
}

protected function regenerateIdHelper(bool $lock, bool $destroy, bool $proxy) {
$this->testRequiresMode('cli');

$data = uniqid('regenerate-id:');
$runner = $this->sessionRunner()
->sleep(0)
Expand Down Expand Up @@ -7652,12 +7685,16 @@ public function testSession_regenerateSessionId_withLock_withDestroy_withProxy(
}

public function testSession_ttl_equalsToSessionLifetime() {
$this->testRequiresMode('cli');

$runner = $this->sessionRunner()->lifetime(600);
$this->assertEquals('SUCCESS', $runner->execFg());
$this->assertEquals(600, $this->redis->ttl($runner->getSessionKey()));
}

public function testSession_ttl_resetOnWrite() {
$this->testRequiresMode('cli');

$runner1 = $this->sessionRunner()->lifetime(600);
$this->assertEquals('SUCCESS', $runner1->execFg());

Expand All @@ -7668,6 +7705,8 @@ public function testSession_ttl_resetOnWrite() {
}

public function testSession_ttl_resetOnRead() {
$this->testRequiresMode('cli');

$data = uniqid(__FUNCTION__);

$runner = $this->sessionRunner()->lifetime(600)->data($data);
Expand Down
10 changes: 5 additions & 5 deletions tests/TestRedis.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php define('PHPREDIS_TESTRUN', true);

require_once(dirname($_SERVER['PHP_SELF'])."/TestSuite.php");
require_once(dirname($_SERVER['PHP_SELF'])."/RedisTest.php");
require_once(dirname($_SERVER['PHP_SELF'])."/RedisArrayTest.php");
require_once(dirname($_SERVER['PHP_SELF'])."/RedisClusterTest.php");
require_once(dirname($_SERVER['PHP_SELF'])."/RedisSentinelTest.php");
require_once __DIR__ . "/TestSuite.php";
require_once __DIR__ . "/RedisTest.php";
require_once __DIR__ . "/RedisArrayTest.php";
require_once __DIR__ . "/RedisClusterTest.php";
require_once __DIR__ . "/RedisSentinelTest.php";

function getClassArray($classes) {
$result = [];
Expand Down
12 changes: 11 additions & 1 deletion tests/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public function getHost() { return $this->host; }
public function getPort() { return $this->port; }
public function getAuth() { return $this->auth; }

public static function errorMessage(string $fmt, ...$args) {
$msg = vsprintf($fmt . "\n", $args);

if (defined('STDERR')) {
fwrite(STDERR, $msg);
} else {
echo $msg;
}
}

public static function make_bold(string $msg) {
return self::$colorize ? self::$BOLD_ON . $msg . self::$BOLD_OFF : $msg;
}
Expand Down Expand Up @@ -516,7 +526,7 @@ public static function loadTestClass($class) {
/* Flag colorization */
public static function flagColorization(bool $override) {
self::$colorize = $override && function_exists('posix_isatty') &&
posix_isatty(STDOUT);
defined('STDOUT') && posix_isatty(STDOUT);
}

public static function run($class_name, ?string $limit = NULL,
Expand Down
Loading
0