-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: resolve race conditions in Redis TTL and prevent cache test state leakage #10374
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| API | ||
| AutoReview | ||
| Autoloader | ||
| # Cache | ||
| Cache | ||
| CLI | ||
| Commands | ||
| Config | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,7 +141,7 @@ public function save(string $key, mixed $value, int $ttl = 60): bool | |
| } | ||
|
|
||
| if ($ttl !== 0) { | ||
| $this->redis->expireAt($key, Time::now()->getTimestamp() + $ttl); | ||
| $this->redis->expire($key, $ttl); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a BC break, please revert. |
||
| } | ||
|
|
||
| return true; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,30 +27,24 @@ | |
| #[RequiresPhpExtension('apcu')] | ||
| final class ApcuHandlerTest extends AbstractHandlerTestCase | ||
| { | ||
| /** | ||
| * @return list<string> | ||
| */ | ||
| private static function getKeyArray(): array | ||
| { | ||
| return [ | ||
| self::$key1, | ||
| self::$key2, | ||
| self::$key3, | ||
| ]; | ||
| } | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| if (! function_exists('apcu_enabled') || ! apcu_enabled()) { | ||
| $this->markTestSkipped('APCu extension is not loaded or not enabled in CLI.'); | ||
| } | ||
|
|
||
| $this->handler = CacheFactory::getHandler(new Cache(), 'apcu'); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| foreach (self::getKeyArray() as $key) { | ||
| $this->handler->delete($key); | ||
| if (! isset($this->handler)) { | ||
| return; | ||
| } | ||
|
|
||
| $this->handler->clean(); | ||
|
Comment on lines
+43
to
+47
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also call |
||
| } | ||
|
|
||
| public function testNew(): void | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,18 +31,6 @@ final class FileHandlerTest extends AbstractHandlerTestCase | |
| private static string $directory = 'FileHandler'; | ||
| private Cache $config; | ||
|
|
||
| /** | ||
| * @return list<string> | ||
| */ | ||
| private static function getKeyArray(): array | ||
| { | ||
| return [ | ||
| self::$key1, | ||
| self::$key2, | ||
| self::$key3, | ||
| ]; | ||
| } | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
@@ -65,19 +53,13 @@ protected function setUp(): void | |
| protected function tearDown(): void | ||
| { | ||
| parent::tearDown(); | ||
| clearstatcache(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? |
||
|
|
||
| if (is_dir($this->config->file['storePath'])) { | ||
| chmod($this->config->file['storePath'], 0777); | ||
|
|
||
| foreach (self::getKeyArray() as $key) { | ||
| if (is_file($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $key)) { | ||
| chmod($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $key, 0777); | ||
| unlink($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $key); | ||
| } | ||
| if (is_file($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $this->config->prefix . $key)) { | ||
| chmod($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $this->config->prefix . $key, 0777); | ||
| unlink($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $this->config->prefix . $key); | ||
| } | ||
| if (isset($this->handler)) { | ||
| $this->handler->clean(); | ||
| } | ||
|
|
||
| rmdir($this->config->file['storePath']); | ||
|
|
@@ -118,7 +100,7 @@ public function testSetDefaultPath(): void | |
| */ | ||
| public function testGet(): void | ||
| { | ||
| $this->handler->save(self::$key1, 'value', 2); | ||
| $this->assertTrue($this->handler->save(self::$key1, 'value', 2)); | ||
|
|
||
| $this->assertSame('value', $this->handler->get(self::$key1)); | ||
| $this->assertNull($this->handler->get(self::$dummy)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a BC break, please revert.