Skip to content

Refactor stale-while-revalidate code in HttpCache, add a (first?) test for it #22043

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

Closed
wants to merge 2 commits into from
Closed

Refactor stale-while-revalidate code in HttpCache, add a (first?) test for it #22043

wants to merge 2 commits into from

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Mar 17, 2017

Q A
Branch? 2.8
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

I came up with this while trying to hunt a production bug related to handling of stale cache entries under the condition of a busy backend (also see #22033).

It's just a refactoring to make the code more readable plus a new test.

* After 10s, the cached response has become stale. Yet, we're still within the "stale_while_revalidate"
* timeout so we may serve the stale response.
*/
sleep(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sleeping for 20 seconds in total in this test is unacceptable. Is it possible to sleep for less, or don't sleep at all?

Copy link
Member

@javiereguiluz javiereguiluz Mar 17, 2017

Choose a reason for hiding this comment

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

With PHPUnitBridge clock mocking, time passes instantly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't @group time-sensitive / clock mocking solve this?

Copy link
Contributor

Choose a reason for hiding this comment

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

It does indeed. I only checked the method annotations (none). Indeed time-sensitive is set on the test class 👍

@mpdude
Copy link
Contributor Author

mpdude commented Mar 21, 2017

@nicolas-grekas should I be concerned because of the failing AppVeyor builds?

@fabpot
Copy link
Member

fabpot commented Mar 22, 2017

Thank you @mpdude.

@fabpot fabpot closed this in 426a666 Mar 22, 2017
@mpdude mpdude deleted the http-cache-stale-while-revalidate branch March 23, 2017 05:35
$this->assertHttpKernelIsNotCalled();
$this->assertEquals(503, $this->response->getStatusCode());
$this->assertEquals('Old response', $this->response->getContent());
}
Copy link
Member

Choose a reason for hiding this comment

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

Dunno why, but this test breaks the HttpKernel test suite on windows (see appveyor https://ci.appveyor.com/project/fabpot/symfony/build/1.0.20167#L841), removing the test fixes it.

@chalasr chalasr mentioned this pull request Mar 30, 2017
chalasr added a commit to chalasr/symfony that referenced this pull request Mar 30, 2017
…ttpCache, add a (first?) test for it (mpdude)"

This reverts commit 426a666, reversing
changes made to 05933f3.
chalasr added a commit to chalasr/symfony that referenced this pull request Mar 30, 2017
…ttpCache, add a (first?) test for it (mpdude)"

This reverts commit 426a666, reversing
changes made to 05933f3.
fabpot added a commit that referenced this pull request Apr 3, 2017
This PR was merged into the 3.3-dev branch.

Discussion
----------

Fix HttpCache test

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #22043 (comment)
| License       | MIT
| Doc PR        | n/a

will make appveyor green.

Commits
-------

3178f50 Fix failing HttpCache test on windows
symfony-splitter pushed a commit to symfony/http-kernel that referenced this pull request Apr 3, 2017
This PR was merged into the 3.3-dev branch.

Discussion
----------

Fix HttpCache test

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | symfony/symfony#22043 (comment)
| License       | MIT
| Doc PR        | n/a

will make appveyor green.

Commits
-------

3178f50 Fix failing HttpCache test on windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants