Skip to content

FOUR-20950: Handle Cache Invalidation for ETags #7817

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

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

eiresendez
Copy link
Contributor

@eiresendez eiresendez commented Dec 11, 2024

Issue & Reproduction Steps

This PR adds a test to ensure that cache invalidation works correctly for routes using the etag middleware with the etag_tables configuration. The existing functionality correctly handled ETag generation and cache invalidation, but there was no explicit test coverage for the scenarios where changes in updated_at in the specified tables should trigger cache invalidation.

  1. Define a route using the etag middleware and specify etag_tables in the route’s defaults.
  2. Perform an initial request to retrieve the ETag.
  3. Update the updated_at column in the database for the specified table.
  4. Expect the ETag to change and invalidation to occur.

Solution

  • Introduced a new test case to verify cache invalidation when the updated_at field in the specified tables changes.
  • Ensured the test validates that the ETag changes after database updates and remains the same if no updates are made.

How to Test

  1. Setup:
  • Create a route using the etag middleware with etag_tables pointing to a database table (e.g., processes).
  1. Run the test:
  • Execute a manual test to ensure the ETag updates correctly when updated_at in the database changes.
  • Validate that:
    • The ETag remains unchanged if there are no updates.
    • The ETag changes after an update to updated_at.
    • A 200 OK is returned when the client sends an outdated ETag.

The functionality now has complete test coverage to ensure the proper behavior of cache invalidation using etag_tables.

Related Tickets & Packages

Code Review Checklist

  • I have pulled this code locally and tested it on my instance, along with any associated packages.
  • This code adheres to ProcessMaker Coding Guidelines.
  • This code includes a unit test or an E2E test that tests its functionality, or is covered by an existing test.
  • This solution fixes the bug reported in the original ticket.
  • This solution does not alter the expected output of a component in a way that would break existing Processes.
  • This solution does not implement any breaking changes that would invalidate documentation or cause existing Processes to fail.
  • This solution has been tested with enterprise packages that rely on its functionality and does not introduce bugs in those packages.
  • This code does not duplicate functionality that already exists in the framework or in ProcessMaker.
  • This ticket conforms to the PRD associated with this part of ProcessMaker.

- Introduced a new test class `HandleEtagCacheInvalidationTest` to verify ETag behavior upon database updates.
- Implemented tests to ensure ETag changes when the underlying data is modified and that the correct ETag is returned for subsequent requests.
- Updated existing `HandleEtagTest` to include a test for returning 304 Not Modified when the ETag matches the client-provided value.
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link
Contributor

@estebangallego estebangallego left a comment

Choose a reason for hiding this comment

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

Works as expected

@eiresendez eiresendez merged commit 24afdfc into epic/FOUR-20929 Dec 13, 2024
9 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants