Skip to content

Conversation

gam6itko
Copy link
Collaborator

@gam6itko gam6itko commented May 27, 2025

Also use initialWaitTtl while lock creation

Summary by CodeRabbit

  • Refactor
    • Updated default timing behavior in token storage and locking mechanisms for improved flexibility.
    • Enhanced compatibility with newer versions of a development tool.
    • Added override attributes to clarify method implementations.
  • Tests
    • Adjusted test cases to align with updated locking behavior and timing defaults.
    • Added parameterized tests to verify timing configurations in token storage.

@gam6itko gam6itko requested a review from butschster May 27, 2025 19:58
Copy link

coderabbitai bot commented May 27, 2025

Walkthrough

The changes update the version constraint for the "vimeo/psalm" dependency in composer.json, add a new runtime dependency "symfony/polyfill-php83", modify the default lock wait time and method signatures in RoadRunnerStore, add #[\Override] attributes to several methods, and adjust corresponding test expectations in RoadRunnerStoreTest. An #[\Override] attribute was also added to the generate() method in RandomTokenGenerator. Additionally, a new parameterized test was introduced to verify TTL and wait TTL handling in RoadRunnerStore.

Changes

File(s) Change Summary
composer.json Updated "vimeo/psalm" version constraint from "^5.9" to "^5.9
src/RoadRunnerStore.php Changed default initialWaitTtl from 60 to 0; updated withTtl method signature to add optional waitTtl; modified lock calls to include initialWaitTtl; added #[\Override] to public methods.
src/RandomTokenGenerator.php Added #[\Override] attribute to the generate() method.
tests/RoadRunnerStoreTest.php Updated test expectations for lock method's fourth argument from 60 to 0 in testWaitAndSaveSuccess and testWaitAndSaveFail; added parameterized test testWithTtl with data provider dataWithTtl.

Poem

A hop to Psalm six, a leap for the store,
Lock waits now zero, not sixty anymore.
Tests keep in step, as rabbits must do,
With code that is nimble, and dependencies new.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5b187c and a0a8b59.

📒 Files selected for processing (2)
  • composer.json (1 hunks)
  • src/RoadRunnerStore.php (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • composer.json
  • src/RoadRunnerStore.php
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/RoadRunnerStoreTest.php (2)

29-42: Consider updating tests to include wait TTL parameters.

The existing testSaveSuccess and testSaveReadSuccess tests should be updated to verify that the wait TTL parameter is correctly passed to the lock methods, similar to how it's tested in testWaitAndSaveSuccess.

Consider updating these tests to use the full method signature:

 $this->rrLock->expects(self::once())
     ->method('lock')
-    ->with('resource-name', 'random-id')
+    ->with('resource-name', 'random-id', 300.0, 0)
     ->willReturn('lock-id');
 $this->rrLock->expects(self::once())
     ->method('lockRead')
-    ->with('resource-name', 'random-id')
+    ->with('resource-name', 'random-id', 300.0, 0)
     ->willReturn('lock-id');

Also applies to: 44-54


95-107: Consider updating failure tests to include wait TTL parameters.

Similar to the success tests, the failure test cases should also verify the complete method signature including the wait TTL parameter.

Update the test expectations to include all parameters:

 $this->rrLock->expects(self::once())
     ->method('lock')
-    ->with('resource-name', 'random-id')
+    ->with('resource-name', 'random-id', 300.0, 0)
     ->willReturn(false);
 $this->rrLock->expects(self::once())
     ->method('lockRead')
-    ->with('resource-name', 'random-id');
+    ->with('resource-name', 'random-id', 300.0, 0)
+    ->willReturn(false);

Also applies to: 109-121

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f339abf and 218d13a.

📒 Files selected for processing (3)
  • composer.json (1 hunks)
  • src/RoadRunnerStore.php (3 hunks)
  • tests/RoadRunnerStoreTest.php (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: static analysis
src/RoadRunnerStore.php

[error] 39-39: MissingOverrideAttribute: Method Spiral\RoadRunner\Symfony\Lock\RoadRunnerStore::save should have the "Override" attribute


[error] 61-61: MissingOverrideAttribute: Method Spiral\RoadRunner\Symfony\Lock\RoadRunnerStore::saveread should have the "Override" attribute


[error] 77-77: MissingOverrideAttribute: Method Spiral\RoadRunner\Symfony\Lock\RoadRunnerStore::exists should have the "Override" attribute


[error] 89-89: MissingOverrideAttribute: Method Spiral\RoadRunner\Symfony\Lock\RoadRunnerStore::putoffexpiration should have the "Override" attribute


[error] 104-104: MissingOverrideAttribute: Method Spiral\RoadRunner\Symfony\Lock\RoadRunnerStore::delete should have the "Override" attribute


[error] 114-114: MissingOverrideAttribute: Method Spiral\RoadRunner\Symfony\Lock\RoadRunnerStore::waitandsave should have the "Override" attribute

🔇 Additional comments (8)
composer.json (1)

37-37:

❓ Verification inconclusive

Verify Psalm 6.0 compatibility and potential breaking changes.

The expansion to include Psalm 6.0 should be verified to ensure there are no breaking changes in static analysis behavior that could affect the codebase.


🌐 Web query:

What are the breaking changes between Psalm 5.9 and Psalm 6.0?

💡 Result:

Psalm 6.0 introduces several breaking changes compared to Psalm 5.9. Key changes include:

  • PHP Version Support: Psalm 6.0 requires PHP 8.1 or higher. (github.com)

  • Amp Library Update: The amphp/amp library has been updated to version 3.0. (github.com)

  • PHP-Parser Upgrade: Psalm now uses nikic/php-parser version 5.0. (github.com)

  • Dictionaries Overhaul: The dictionaries have been completely overhauled, providing more accurate and up-to-date signatures for PHP and extension functions and methods. (newreleases.io)

  • Default Configuration Changes:

    • The ignoreInternalFunctionFalseReturn and ignoreInternalFunctionNullReturn settings are now false by default. This means Psalm will warn when a native function's false or null return type is not explicitly checked. (newreleases.io)
  • Codebase Modernization: The codebase has been modernized for higher performance. (newreleases.io)

For a comprehensive list of breaking changes, refer to the Psalm 6.0.0 release notes.

Citations:


Verify project compatibility with Psalm 6.0 breaking changes

Before merging the expanded constraint ("vimeo/psalm": "^5.9 || ^6.0"), please confirm the codebase and CI environment are ready for Psalm 6.0’s known breaking changes:

  • PHP version: Psalm 6.0 requires PHP 8.1 or higher. Ensure your composer.json and deployment targets are updated accordingly.
  • amphp/amp 3.0 upgrade: Review any async code that depends on Amp’s API for compatibility with v3.
  • nikic/php-parser 5.0: Verify that any custom plugins or tooling consuming php-parser still work as expected.
  • Default config changes: Psalm now warns on unchecked false or null returns by default (ignoreInternalFunctionFalseReturn and ignoreInternalFunctionNullReturn are false). Update your psalm.xml if you need to maintain previous behavior.
  • Dictionaries overhaul & performance tweaks: Run a full Psalm 6.0 analysis and address any new issues or altered type checks.
src/RoadRunnerStore.php (5)

28-28: Significant behavior change - verify this aligns with intended usage.

Changing the default initialWaitTtl from 60 seconds to 0 seconds fundamentally changes the lock acquisition behavior. With 0, lock acquisition will fail immediately if the lock is not available, rather than waiting up to 60 seconds.

Ensure this aligns with the intended usage patterns and that consumers of this library are aware of this breaking change.


34-36: Good enhancement to make wait TTL configurable.

The updated withTtl method signature now allows consumers to specify both the lock TTL and wait TTL, providing more flexibility. The implementation correctly uses the provided waitTtl parameter instead of the instance's initialWaitTtl.


49-49: Consistent implementation of wait TTL parameter.

The lock method call now correctly includes the initialWaitTtl as the fourth parameter, matching the expected interface signature.


68-68: Consistent implementation of wait TTL parameter for read locks.

The lockRead method call now correctly includes the initialWaitTtl as the fourth parameter, maintaining consistency with the lock method.


39-39:

❓ Verification inconclusive

Address missing Override attributes flagged by static analysis.

The pipeline failures indicate that several interface methods are missing #[Override] attributes. While not part of the current changes, these should be addressed to comply with static analysis requirements.

Also applies to: 61-61, 77-77, 89-89, 104-104, 114-114


🏁 Script executed:

#!/bin/bash
# Check which interfaces these methods are implementing to confirm Override attribute requirements
ast-grep --pattern $'interface $_ {
  $$$
  function save($_): $_;
  $$$
}'

ast-grep --pattern $'interface $_ {
  $$$
  function saveRead($_): $_;
  $$$
}'

ast-grep --pattern $'interface $_ {
  $$$
  function exists($_): $_;
  $$$
}'

Length of output: 236


Add missing #[Override] attributes for interface implementations

Our static analysis is failing because several methods in src/RoadRunnerStore.php implement interface contracts but lack the required #[Override] attribute. Please:

• In src/RoadRunnerStore.php, add #[Override] above each of the following method signatures:
– Line 39: public function save(Key $key): void
– Line 61: public function saveRead(Key $key, …): …
– Line 77: public function exists(Key $key): bool
– Line 89, Line 104, Line 114: (other interface-implementing methods)

• Confirm which interfaces each method implements (they may be defined in external packages) and ensure the attribute is applied consistently across all overridden methods.

This will resolve the pipeline failures related to missing #[Override] annotations.

🧰 Tools
🪛 GitHub Actions: static analysis

[error] 39-39: MissingOverrideAttribute: Method Spiral\RoadRunner\Symfony\Lock\RoadRunnerStore::save should have the "Override" attribute

tests/RoadRunnerStoreTest.php (2)

169-169: Test expectation correctly updated to match new default.

The test expectation has been properly updated from 60 to 0 to reflect the new default initialWaitTtl value.


187-187: Test expectation correctly updated to match new default.

Consistent with the other test case, this expectation has been properly updated to reflect the new default wait TTL value.

@butschster butschster requested a review from roxblnfk May 27, 2025 20:23
@butschster butschster added the enhancement New feature or request label May 27, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/RoadRunnerStoreTest.php (1)

194-233: Good test coverage for the new withTtl method signature.

The new parameterized test provides solid coverage for the updated withTtl method that now accepts an optional waitTtl parameter. The data provider covers key scenarios including null, fractional, and zero values.

Consider adding test cases for edge scenarios such as:

  • Negative TTL/waitTtl values (if they should be handled)
  • Very large values
  • Invalid input types (if applicable)

To enhance test coverage, consider adding these test cases to the data provider:

+        yield 'large values' => [
+            3600,
+            1800,
+            3600,
+            1800,
+        ];
+
+        yield 'negative ttl' => [
+            -1,
+            null,
+            -1,
+            0,
+        ];
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d97f929 and c5b187c.

📒 Files selected for processing (2)
  • src/RoadRunnerStore.php (7 hunks)
  • tests/RoadRunnerStoreTest.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/RoadRunnerStore.php
🔇 Additional comments (1)
tests/RoadRunnerStoreTest.php (1)

169-169: LGTM! Test expectations correctly updated to reflect new default value.

The test expectations have been properly updated to use 0 instead of 60 as the fourth argument (initialWaitTtl), which correctly aligns with the PR objective to change the default initialWaitTtl from 60 to 0 seconds.

Also applies to: 187-187

@gam6itko gam6itko requested a review from roxblnfk May 29, 2025 21:18
@roxblnfk roxblnfk changed the title $initialWaitTtl = 0 (sec) by default; 60 - is too big value Set initialWaitTtl = 0; add $waitTtl param to withTtl() May 30, 2025
@roxblnfk roxblnfk merged commit 389f82c into 1.x May 30, 2025
6 checks passed
@roxblnfk roxblnfk deleted the init_wait_ttl branch May 30, 2025 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants