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

intersphinx: fix flipped use of intersphinx_cache_limit. #12905

Merged

Conversation

troiganto
Copy link
Contributor

Subject: intersphinx: fix flipped use of intersphinx_cache_limit.

Feature or Bugfix

  • Bugfix

Purpose

Follow-up to #12514, which fixed one bug surrounding intersphinx_cache_limit, but introduced another by flipping a comparison.

Detail

The previous patch properly took negative cache limits into account (which are meant to always keep the cache). However, in the process, it flipped the comparison between intersphinx_cache_limit and zero. The consequence was that the cache was always kept for positive values, and always refreshed for negative values.

The provided unit test didn't catch the mistake because it merely checked the return value of _fetch_inventory_group(), which is True if the cache has been updated successfully. However, what should've been tested was whether we tried to update the cache.

The problem was that the test attempted to fetch the remote inventory from a nonsense address, which is reasonable for a test. However, the fetch fails, as expected. And correctly Sphinx tells us that the cache wasn't updated, even though it tried to.

The new test replaces the inner fetch function with a mock that always returns some data. This means that "did we try to update the cache" and "did we successfullt update the cache" are now the same. It also lets us query the mock directly whether it has been called or not.

In addition, the test also has been parametrized over multiple values. This way, we test not only the first of the following cases of interest, but all three:

  1. negative cache limit
  2. positive cache limit, cache fresh
  3. positive cache limit, cache stale

Relates

Follow-up to sphinx-doc#12514. The previous patch properly took negative cache
limits into account (which are meant to always keep the cache). However,
in the process, it flipped the comparison between
`intersphinx_cache_limit` and zero. The consequence was that the cache
was always kept for positive values, and always refreshed for negative
values.

The provided unit test didn't catch the mistake because it merely
checked the return value of `_fetch_inventory_group()`, which is True if
the cache has been updated *successfully*. However, what should've been
tested was whether we *tried* to update the cache.

The problem was that the test attempted to fetch the remote inventory
from a nonsense address, which is reasonable for a test. However, the
fetch fails, as expected. And correctly Sphinx tells us that the cache
wasn't updated, even though it *tried to*.

The new test replaces the inner fetch function with a mock that always
returns some data. This means that "did we try to update the cache" and
"did we successfullt update the cache" are now the same. It also lets us
query the mock directly whether it has been called or not.

In addition, the test also has been parametrized over multiple values.
This way, we test not only the first of the following cases of interest,
but all three:

1. negative cache limit
2. positive cache limit, cache fresh
2. positive cache limit, cache stale
@troiganto troiganto force-pushed the flip-check-intersphinx-cache-limit branch from 62d71c0 to 65703ee Compare September 20, 2024 23:06
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

I'm extremely sorry for the inconvenience. I should stop reviewing PRs and accepting them when I'm still sleepy or too tired. By the way, thank you for the tests (I am now tired so I'll still ask @AA-Turner to have a final check).

tests/test_extensions/test_ext_intersphinx.py Show resolved Hide resolved
Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

Thank you Nico (@troiganto) for the excellent description and PR, sorry it took too long to review.

A

@AA-Turner AA-Turner added this to the 8.1.0 milestone Oct 7, 2024
@AA-Turner AA-Turner merged commit cc1b13c into sphinx-doc:master Oct 7, 2024
23 checks passed
@troiganto
Copy link
Contributor Author

np, thanks for the maintenance work! contributing was a lot simpler than for other projects, so I actually had a great time solving this!

@SilverRainZ
Copy link
Contributor

I am sorry for introducing another bug when fixing a bug. Thanks for fixing this, I learned more unit test tips from this PR.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants