Skip to content

Commit

Permalink
fix unit test ensure all cache are overdue
Browse files Browse the repository at this point in the history
  • Loading branch information
godruoyi committed Apr 7, 2024
1 parent 063e5cf commit f3395ab
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions tests/RedisSequenceResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace Tests;

use Godruoyi\Snowflake\RedisSequenceResolver;
use Godruoyi\Snowflake\Snowflake;
use RedisException;

class RedisSequenceResolverTest extends TestCase
Expand Down Expand Up @@ -69,19 +68,17 @@ public function test_real_redis(): void
$redis = new \Redis();
$redis->connect($host, $port | 0);

// Sometimes running these tests in parallel on Github may cause unexpected errors,
// so we change to use random here.
$key = (new Snowflake())->getCurrentMillisecond();
$randomKey = random_int(0, 99999);

$redisResolver = new RedisSequenceResolver($redis);

$this->assertEquals(0, $redisResolver->sequence($key));
$this->assertEquals(1, $redisResolver->sequence($key));
$this->assertEquals(2, $redisResolver->sequence($key));
$this->assertEquals(3, $redisResolver->sequence($key));
$this->assertEquals(0, $redisResolver->sequence($randomKey));
$this->assertEquals(1, $redisResolver->sequence($randomKey));
$this->assertEquals(2, $redisResolver->sequence($randomKey));
$this->assertEquals(3, $redisResolver->sequence($randomKey));

sleep(10);
sleep(11);

$this->assertEquals(0, $redisResolver->sequence($key));
$this->assertEquals(0, $redisResolver->sequence($randomKey));
}
}

0 comments on commit f3395ab

Please sign in to comment.