Explorar o código

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

Daniele Alessandri %!s(int64=9) %!d(string=hai) anos
pai
achega
fc18e6456a

+ 6 - 5
tests/Predis/Command/KeyExpireAtTest.php

@@ -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->assertTrue($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->assertFalse($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->assertTrue($redis->expireat('foo', $now - 100));
         $this->assertFalse($redis->exists('foo'));

+ 2 - 19
tests/Predis/Command/KeyExpireTest.php

@@ -77,32 +77,15 @@ class KeyExpireTest extends PredisCommandTestCase
     {
         $redis = $this->getClient();
 
-        $redis->set('foo', 'bar');
+        $this->assertEquals('OK', $redis->set('foo', 'bar'));
 
         $this->assertTrue($redis->expire('foo', 1));
         $this->assertSame(1, $redis->ttl('foo'));
 
         $this->sleep(2.0);
-
         $this->assertFalse($redis->exists('foo'));
     }
 
-    /**
-     * @medium
-     * @group connected
-     * @group slow
-     */
-    public function testConsistencyWithTTL()
-    {
-        $redis = $this->getClient();
-
-        $redis->set('foo', 'bar');
-
-        $this->assertTrue($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->assertTrue($redis->expire('foo', -10));
         $this->assertFalse($redis->exists('foo'));

+ 2 - 3
tests/Predis/Command/KeyPreciseExpireAtTest.php

@@ -68,13 +68,12 @@ class KeyPreciseExpireAtTest extends PredisCommandTestCase
         $ttl = 1.5;
         $redis = $this->getClient();
 
-        $redis->set('foo', 'bar');
+        $this->assertEquals('OK', $redis->set('foo', 'bar'));
 
         $this->assertTrue($redis->pexpireat('foo', time() + $ttl * 1000));
         $this->assertLessThan($ttl * 1000, $redis->pttl('foo'));
 
         $this->sleep($ttl + 0.5);
-
         $this->assertFalse($redis->exists('foo'));
     }
 
@@ -85,7 +84,7 @@ class KeyPreciseExpireAtTest extends PredisCommandTestCase
     {
         $redis = $this->getClient();
 
-        $redis->set('foo', 'bar');
+        $this->assertEquals('OK', $redis->set('foo', 'bar'));
 
         $this->assertTrue($redis->expireat('foo', time() - 100000));
         $this->assertFalse($redis->exists('foo'));

+ 8 - 9
tests/Predis/Command/KeyPreciseExpireTest.php

@@ -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->assertTrue($redis->pexpire('foo', $ttl));
 
         $this->sleep(1.2);
@@ -92,16 +91,16 @@ class KeyPreciseExpireTest extends PredisCommandTestCase
      */
     public function testConsistencyWithTTL()
     {
-        $ttl = 1 * 1000;
+        $ttl = 1000;
         $redis = $this->getClient();
 
-        $redis->set('foo', 'bar');
-
+        $this->assertEquals('OK', $redis->set('foo', 'bar'));
         $this->assertTrue($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 +110,7 @@ class KeyPreciseExpireTest extends PredisCommandTestCase
     {
         $redis = $this->getClient();
 
-        $redis->set('foo', 'bar');
+        $this->assertEquals('OK', $redis->set('foo', 'bar'));
 
         $this->assertTrue($redis->pexpire('foo', -10000));
         $this->assertFalse($redis->exists('foo'));

+ 4 - 2
tests/Predis/Command/StringSetExpireTest.php

@@ -63,8 +63,9 @@ class StringSetExpireTest extends PredisCommandTestCase
         $redis = $this->getClient();
 
         $this->assertEquals('OK', $redis->setex('foo', 10, 'bar'));
+
         $this->assertTrue($redis->exists('foo'));
-        $this->assertEquals(10, $redis->ttl('foo'));
+        $this->assertSame(10, $redis->ttl('foo'));
     }
 
     /**
@@ -76,7 +77,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->assertFalse($redis->exists('foo'));
     }