Skip to content
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

[3.0] 优化 ttl 相关测试 #638

Draft
wants to merge 2 commits into
base: 3.0
Choose a base branch
from
Draft
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
34 changes: 20 additions & 14 deletions tests/unit/Component/Tests/BaseCacheTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ public function testSetTTL(): void
{
$this->markTestSkipped('Handler does not support TTL');
}

Assert::assertTrue(CacheManager::set($this->cacheName, 'imi', 'nb', 1));
Assert::assertEquals('nb', CacheManager::get($this->cacheName, 'imi'));

$this->go(function (): void {
Assert::assertTrue(CacheManager::set($this->cacheName, 'imi', 'nb', 1));
Assert::assertEquals('nb', CacheManager::get($this->cacheName, 'imi'));
sleep(2);
usleep(1_100_000);
clearstatcache();
Assert::assertEquals('none', CacheManager::get($this->cacheName, 'imi', 'none'));
}, null, 3);
}, null, 5);
}

public function testSetMultiple(): void
Expand All @@ -58,20 +61,23 @@ public function testSetMultipleTTL(): void
{
$this->markTestSkipped('Handler does not support TTL');
}
$this->go(function (): void {
$values = [
'k1' => 'v1',
'k2' => 'v2',
];
Assert::assertTrue(CacheManager::setMultiple($this->cacheName, $values, 1));
$getValues = CacheManager::getMultiple($this->cacheName, array_keys_string($values));
Assert::assertEquals($values, $getValues);
sleep(2);

$values = [
'k1' => 'v1',
'k2' => 'v2',
];
Assert::assertTrue(CacheManager::setMultiple($this->cacheName, $values, 1));
$getValues = CacheManager::getMultiple($this->cacheName, array_keys_string($values));
Assert::assertEquals($values, $getValues);

$this->go(function () use ($values): void {
usleep(1_100_000);
clearstatcache();
Assert::assertEquals([
'k1' => 'none',
'k2' => 'none',
], CacheManager::getMultiple($this->cacheName, array_keys_string($values), 'none'));
}, null, 3);
}, null, 5);
}

public function testDelete(): void
Expand Down
Loading