Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarius Meissner <marius.meissner@sixt.com>2018-05-22 18:24:47 +0300
committerMarius Meissner <marius.meissner@sixt.com>2018-05-22 18:24:47 +0300
commite2d5b5ea495b93e40392b6c694cb240f2a4dd486 (patch)
tree72d46527eed84821322990a0d0dd9acc4e437ee7 /tests
parent97bb6bd85e3fa38dbb13b97c50bd315490265a80 (diff)
PHPREDIS-1354: Added session TTL tests
Diffstat (limited to 'tests')
-rw-r--r--tests/RedisTest.php42
-rw-r--r--tests/startSession.php6
2 files changed, 42 insertions, 6 deletions
diff --git a/tests/RedisTest.php b/tests/RedisTest.php
index 15c216a0..da4e2523 100644
--- a/tests/RedisTest.php
+++ b/tests/RedisTest.php
@@ -5217,7 +5217,7 @@ class Redis_Test extends TestSuite
$this->assertFalse($this->redis->exists($this->sessionPrefix . $sessionId . '_LOCK'));
}
- public function testSession_ttlMaxExecutionTime()
+ public function testSession_lock_ttlMaxExecutionTime()
{
$this->setSessionHandler();
$sessionId = $this->generateSessionId();
@@ -5233,7 +5233,7 @@ class Redis_Test extends TestSuite
$this->assertTrue($sessionSuccessful);
}
- public function testSession_ttlLockExpire()
+ public function testSession_lock_ttlLockExpire()
{
$this->setSessionHandler();
$sessionId = $this->generateSessionId();
@@ -5468,6 +5468,37 @@ class Redis_Test extends TestSuite
$this->assertEquals('bar', $this->getSessionData($newSessionId));
}
+ public function testSession_ttl_equalsToSessionLifetime()
+ {
+ $sessionId = $this->generateSessionId();
+ $this->startSessionProcess($sessionId, 0, false, 300, true, null, -1, 0, 'test', 600);
+ $ttl = $this->redis->ttl($this->sessionPrefix . $sessionId);
+
+ $this->assertEquals(600, $ttl);
+ }
+
+ public function testSession_ttl_resetOnWrite()
+ {
+ $sessionId = $this->generateSessionId();
+ $this->startSessionProcess($sessionId, 0, false, 300, true, null, -1, 0, 'test', 600);
+ $this->redis->expire($this->sessionPrefix . $sessionId, 9999);
+ $this->startSessionProcess($sessionId, 0, false, 300, true, null, -1, 0, 'test', 600);
+ $ttl = $this->redis->ttl($this->sessionPrefix . $sessionId);
+
+ $this->assertEquals(600, $ttl);
+ }
+
+ public function testSession_ttl_resetOnRead()
+ {
+ $sessionId = $this->generateSessionId();
+ $this->startSessionProcess($sessionId, 0, false, 300, true, null, -1, 0, 'test', 600);
+ $this->redis->expire($this->sessionPrefix . $sessionId, 9999);
+ $this->getSessionData($sessionId);
+ $ttl = $this->redis->ttl($this->sessionPrefix . $sessionId);
+
+ $this->assertEquals(600, $ttl);
+ }
+
private function setSessionHandler()
{
$host = $this->getHost() ?: 'localhost';
@@ -5503,15 +5534,18 @@ class Redis_Test extends TestSuite
* @param int $lock_expires
* @param string $sessionData
*
+ * @param int $sessionLifetime
+ *
* @return bool
+ * @throws Exception
*/
- private function startSessionProcess($sessionId, $sleepTime, $background, $maxExecutionTime = 300, $locking_enabled = true, $lock_wait_time = null, $lock_retries = -1, $lock_expires = 0, $sessionData = '')
+ private function startSessionProcess($sessionId, $sleepTime, $background, $maxExecutionTime = 300, $locking_enabled = true, $lock_wait_time = null, $lock_retries = -1, $lock_expires = 0, $sessionData = '', $sessionLifetime = 1440)
{
if (substr(php_uname(), 0, 7) == "Windows"){
$this->markTestSkipped();
return true;
} else {
- $commandParameters = array($this->getHost(), $sessionId, $sleepTime, $maxExecutionTime, $lock_retries, $lock_expires, $sessionData);
+ $commandParameters = array($this->getHost(), $sessionId, $sleepTime, $maxExecutionTime, $lock_retries, $lock_expires, $sessionData, $sessionLifetime);
if ($locking_enabled) {
$commandParameters[] = '1';
diff --git a/tests/startSession.php b/tests/startSession.php
index 081a6951..4317f747 100644
--- a/tests/startSession.php
+++ b/tests/startSession.php
@@ -8,6 +8,7 @@ $maxExecutionTime = $argv[4];
$lock_retries = $argv[5];
$lock_expire = $argv[6];
$sessionData = $argv[7];
+$sessionLifetime = $argv[8];
if (empty($redisHost)) {
$redisHost = 'localhost';
@@ -18,13 +19,14 @@ ini_set('session.save_path', 'tcp://' . $redisHost . ':6379');
ini_set('max_execution_time', $maxExecutionTime);
ini_set('redis.session.lock_retries', $lock_retries);
ini_set('redis.session.lock_expire', $lock_expire);
+ini_set('session.gc_maxlifetime', $sessionLifetime);
if (isset($argv[8])) {
- ini_set('redis.session.locking_enabled', $argv[8]);
+ ini_set('redis.session.locking_enabled', $argv[9]);
}
if (isset($argv[9])) {
- ini_set('redis.session.lock_wait_time', $argv[9]);
+ ini_set('redis.session.lock_wait_time', $argv[10]);
}
session_id($sessionId);