[tests] Apply small changes to commands tests with expirations.

This commit is contained in:
Daniele Alessandri
2015-07-25 09:24:49 +02:00
parent d0012e67ff
commit 59798e1f9e
5 changed files with 25 additions and 39 deletions
+6 -5
View File
@@ -78,13 +78,14 @@ class KeyExpireAtTest extends PredisCommandTestCase
$redis = $this->getClient();
$now = time();
$redis->set('foo', 'bar');
$this->assertEquals('OK', $redis->set('foo', 'bar'));
$this->assertSame(1, $redis->expireat('foo', $now + 1));
$this->assertLessThanOrEqual(1, $redis->ttl('foo'));
$this->sleep(2);
$this->assertThat($redis->ttl('foo'), $this->logicalAnd(
$this->greaterThanOrEqual(0), $this->lessThanOrEqual(1)
));
$this->sleep(2.0);
$this->assertSame(0, $redis->exists('foo'));
}
@@ -96,7 +97,7 @@ class KeyExpireAtTest extends PredisCommandTestCase
$redis = $this->getClient();
$now = time();
$redis->set('foo', 'bar');
$this->assertEquals('OK', $redis->set('foo', 'bar'));
$this->assertSame(1, $redis->expireat('foo', $now - 100));
$this->assertSame(0, $redis->exists('foo'));
+2 -19
View File
@@ -77,32 +77,15 @@ class KeyExpireTest extends PredisCommandTestCase
{
$redis = $this->getClient();
$redis->set('foo', 'bar');
$this->assertEquals('OK', $redis->set('foo', 'bar'));
$this->assertSame(1, $redis->expire('foo', 1));
$this->assertSame(1, $redis->ttl('foo'));
$this->sleep(2.0);
$this->assertSame(0, $redis->exists('foo'));
}
/**
* @medium
* @group connected
* @group slow
*/
public function testConsistencyWithTTL()
{
$redis = $this->getClient();
$redis->set('foo', 'bar');
$this->assertSame(1, $redis->expire('foo', 10));
$this->sleep(1.5);
$this->assertLessThan(10, $redis->ttl('foo'));
}
/**
* @group connected
*/
@@ -110,7 +93,7 @@ class KeyExpireTest extends PredisCommandTestCase
{
$redis = $this->getClient();
$redis->set('foo', 'bar');
$this->assertEquals('OK', $redis->set('foo', 'bar'));
$this->assertSame(1, $redis->expire('foo', -10));
$this->assertSame(0, $redis->exists('foo'));
+11 -11
View File
@@ -75,11 +75,10 @@ class KeyPreciseExpireTest extends PredisCommandTestCase
*/
public function testCanExpireKeys()
{
$ttl = 1 * 1000;
$ttl = 1000;
$redis = $this->getClient();
$redis->set('foo', 'bar');
$this->assertEquals('OK', $redis->set('foo', 'bar'));
$this->assertSame(1, $redis->pexpire('foo', $ttl));
$this->sleep(1.2);
@@ -87,21 +86,22 @@ class KeyPreciseExpireTest extends PredisCommandTestCase
}
/**
* @medium
* @group connected
* @group slow
*/
public function testConsistencyWithTTL()
{
$ttl = 1 * 1000;
public function testConsistencyWithTTL()
{
$ttl = 1000;
$redis = $this->getClient();
$redis->set('foo', 'bar');
$this->assertEquals('OK', $redis->set('foo', 'bar'));
$this->assertSame(1, $redis->pexpire('foo', $ttl));
$this->sleep(0.5);
$this->assertLessThanOrEqual($ttl, $redis->pttl('foo'));
$this->assertGreaterThan($ttl - 800, $redis->pttl('foo'));
$this->assertThat($redis->pttl('foo'), $this->logicalAnd(
$this->lessThanOrEqual($ttl), $this->greaterThan($ttl - 800)
));
}
/**
@@ -111,7 +111,7 @@ class KeyPreciseExpireTest extends PredisCommandTestCase
{
$redis = $this->getClient();
$redis->set('foo', 'bar');
$this->assertEquals('OK', $redis->set('foo', 'bar'));
$this->assertSame(1, $redis->pexpire('foo', -10000));
$this->assertSame(0, $redis->exists('foo'));
@@ -64,7 +64,7 @@ class StringPreciseSetExpireTest extends PredisCommandTestCase
$this->assertEquals('OK', $redis->psetex('foo', 10000, 'bar'));
$this->assertSame(1, $redis->exists('foo'));
$this->assertEquals(10, $redis->ttl('foo'));
$this->assertSame(10, $redis->ttl('foo'));
}
/**
@@ -75,7 +75,8 @@ class StringPreciseSetExpireTest extends PredisCommandTestCase
{
$redis = $this->getClient();
$redis->psetex('foo', 50, 'bar');
$this->assertEquals('OK', $redis->psetex('foo', 50, 'bar'));
$this->sleep(0.5);
$this->assertSame(0, $redis->exists('foo'));
}
+3 -2
View File
@@ -64,7 +64,7 @@ class StringSetExpireTest extends PredisCommandTestCase
$this->assertEquals('OK', $redis->setex('foo', 10, 'bar'));
$this->assertSame(1, $redis->exists('foo'));
$this->assertEquals(10, $redis->ttl('foo'));
$this->assertSame(10, $redis->ttl('foo'));
}
/**
@@ -76,7 +76,8 @@ class StringSetExpireTest extends PredisCommandTestCase
{
$redis = $this->getClient();
$redis->setex('foo', 1, 'bar');
$this->assertEquals('OK', $redis->setex('foo', 1, 'bar'));
$this->sleep(2.0);
$this->assertSame(0, $redis->exists('foo'));
}