Skip to content

fix(test): make Test_scitag.py independent of the live scitags.org API - #9003

Merged
aldbr merged 1 commit into
DIRACGrid:integrationfrom
fstagni:fix/scitag-flaky-tests
Dec 4, 2026
Merged

aldbr merged 1 commit into
DIRACGrid:integrationfrom
fstagni:fix/scitag-flaky-tests

Conversation

@fstagni

@fstagni fstagni commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

BEGIN_PR_BODY

Description

The scitag unit tests were failing in CI (e.g. this run) because get_scitag() resolves VO/activity ids from the live https://scitags.org/api.json, while the tests asserted against ids hardcoded from a past snapshot of that API:

  • atlas Analysis Output is now activityId=12 upstream (test expected 18) → assert 140 == 146
  • atlas Debug no longer matches (test expected 9) → falls back to default → assert 129 == 137
  • any transient failure of the HTTP fetch also silently falls back to defaults, making the tests depend on network availability.

This PR makes the tests hermetic:

  • requests.get is mocked with a static fixture mirroring the api.json structure, so results are deterministic.
  • the module-level TTL caches (_scitag_cache, _scitag_json_cache) are cleared around each test so cached real-network results cannot leak into the tests.
  • two tests are added covering the network-failure fallback to defaults, and that the API is fetched at most once (cache behaviour).

The suite now runs in <1s with no network access.

Local tests (with ANA eras)

  • TESTDIRAC: Integration test (macOS)
  • TESTDIRAC: Unit tests

END_PR_BODY

get_scitag() fetches https://scitags.org/api.json, but the unit tests
asserted against VO/activity ids hardcoded from a past snapshot of that
API. scitags.org has since evolved (e.g. atlas 'Analysis Output' moved
from activityId 18 to 12, 'Debug' no longer matches), and the fetch can
also fail outright in CI, so the tests were flaky.

Mock the network call with a static fixture, clear the module-level
caches around each test, and add coverage for the network-failure
fallback and the fetch-once caching behaviour.

@aldbr aldbr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, but how do we now make sure we are not drifting apart from https://scitags.org/api.json?

@fstagni

fstagni commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

The schema should not be changing.

@aldbr

aldbr commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Well, but as we can see it just changed 😅
If you have any documentation saying it should not change anymore, then please add it in a comment so that we remember

@fstagni

fstagni commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

The schema did not change, the value in it might

@aldbr

aldbr commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Oh indeed I see, then LGTM

@aldbr
aldbr merged commit 9adb3f5 into DIRACGrid:integration Dec 4, 2026
26 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