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

test: refactor usage within test_local #8913

Merged
merged 8 commits into from
Mar 4, 2024

Conversation

wes-turner
Copy link
Contributor

@wes-turner wes-turner commented Feb 28, 2024

Fixes test-det-deploy-local tests that were broken by a change in caching strategy in #8872.

Changes to test_local.py:

  • changed interface to functions bringing up and down resources to be both more general and more explicit
  • resources in the tests themselves are brought up and down using a context manager. This ensures they clean up after themselves even when they fail.
  • deleted a couple functions that had been needed for the previously-deleted test-stress.

Changes to api_utils.py:

  • is_hpc operates directly on a passed session.

Changes to experiment.py & compute-stats.py

  • The session for a run experiment is passed to api_utils.is_hpc so that this function can query the now-live master to determine whether that master is running an HPC scheduler. Previous calls to is_hpc only accidentally worked because the very first time it was called it brought up a master that happened to run at the same default location as the session is_hpc generated by default.
  • Formatting

Description

Test Plan

Commentary (optional)

Checklist

  • Changes have been manually QA'd
  • User-facing API changes need the "User-facing API Change" label.
  • Release notes should be added as a separate file under docs/release-notes/.
    See Release Note for details.
  • Licenses should be included for new code which was copied and/or modified from any external code.

Ticket

@cla-bot cla-bot bot added the cla-signed label Feb 28, 2024
Copy link

netlify bot commented Feb 28, 2024

Deploy Preview for determined-ui ready!

Name Link
🔨 Latest commit 45b137c
🔍 Latest deploy log https://app.netlify.com/sites/determined-ui/deploys/65e61338009c3c00080bd63d
😎 Deploy Preview https://deploy-preview-8913--determined-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@wes-turner wes-turner changed the title Wes/refactor test deploy local test: refactor usage within test_local Feb 28, 2024
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 47.22%. Comparing base (fa856ab) to head (45b137c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8913   +/-   ##
=======================================
  Coverage   47.22%   47.22%           
=======================================
  Files        1162     1162           
  Lines      175910   175910           
  Branches     2235     2235           
=======================================
  Hits        83066    83066           
  Misses      92686    92686           
  Partials      158      158           
Flag Coverage Δ
backend 42.09% <ø> (ø)
harness 63.94% <ø> (ø)
web 42.53% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@wes-turner wes-turner force-pushed the wes/refactor-test-deploy-local branch 2 times, most recently from 221f3aa to deed490 Compare February 28, 2024 19:44
@wes-turner wes-turner marked this pull request as ready for review February 28, 2024 20:26
@wes-turner wes-turner requested a review from a team as a code owner February 28, 2024 20:26
@functools.lru_cache(maxsize=1)
def _get_scheduler_type() -> Optional[bindings.v1SchedulerType]:
scheduler_type: Optional[bindings.v1SchedulerType]
@functools.lru_cache()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It feels slightly better from an interface perspective to put the optional session parameter (and its creation) into the callers of these primitives (like skipif_not_hpc).

Let's take _get_scheduler_type and skipif_not_hpc explicitly.

If we move the session into skipif_not_hpc, then in the case no session is passed (like during all the skipifs) then a session will be created inside skipif_not_hpc. This session creation involves a login, which may fail after trying to find master if master isn't responsive. So we put that into a try and probably cache skipif_not_hpc, too, so we don't mindlessly try to log in a thousand times.

But the functools cache treats each parameter a function gets as necessary, and skipif_not_hpc also takes a reason. It seems wrong to bust the cache if that reason changes.

I think the design that makes the most sense is for skipif_not_hpc to take a required session. But then this makes pytest have to create those sessions explicitly while it's gathering tests. Which, it's at runtime that we'll be most certain of where master has been brought up, so this makes sense. But it's also a bigger refactor than I want to do, here.

In the end, my preference is for this suboptimal solution rather than the solution that moves session creation to callers.

But maybe that's wrong or maybe there's another approach entirely. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OOB discussion led to not changing these methods to take an optional session.

Copy link
Contributor

@NicholasBlaskey NicholasBlaskey left a comment

Choose a reason for hiding this comment

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

these changes make sense to me

I'm not going to review or approve just because I'm not a codeowner in this area

Comment on lines 515 to 522
1
if t.trial.state
in [
bindings.trialv1State.RUNNING,
bindings.trialv1State.STARTING,
bindings.trialv1State.PULLING,
]
else 0
Copy link
Member

Choose a reason for hiding this comment

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

recommend deleting 1 if and else 0. Just a nit.

Copy link
Contributor Author

@wes-turner wes-turner Mar 1, 2024

Choose a reason for hiding this comment

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

Nice. This let me remove the parens without my formatter adding them back in.

max_secs_to_free_slots = 300 if api_utils.is_hpc() else 30
max_secs_to_free_slots = 300 if api_utils.is_hpc(sess) else 30
Copy link
Member

Choose a reason for hiding this comment

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

is this the only place you have caching issues? Or did I miss another place while skimming through the changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved OOB, this plus one other place I also missed and am adding.

@wes-turner wes-turner force-pushed the wes/refactor-test-deploy-local branch from 7b3c07a to dbb0a80 Compare March 1, 2024 23:57
Copy link
Member

@rb-determined-ai rb-determined-ai left a comment

Choose a reason for hiding this comment

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

nice

This still allows the skipif decorators to all be cached during test
collection, while giving tests themselves the opportunity to pass
explicit sessions and get new results from there.
@wes-turner wes-turner force-pushed the wes/refactor-test-deploy-local branch from dbb0a80 to 45b137c Compare March 4, 2024 18:30
@wes-turner wes-turner merged commit f416354 into main Mar 4, 2024
74 of 85 checks passed
@wes-turner wes-turner deleted the wes/refactor-test-deploy-local branch March 4, 2024 19:25
maxrussell pushed a commit that referenced this pull request Mar 21, 2024
Fixes `test-det-deploy-local` tests that were broken by a change in caching strategy in #8872.

Changes to test_local.py:
* changed interface to functions bringing up and down resources to be both more general and more explicit
* resources in the tests themselves are brought up and down using a context manager. This ensures they clean up after themselves even when they fail.
* deleted a couple functions that had been needed for the previously-deleted `test-stress`.

Changes to api_utils.py:
* `is_hpc` operates directly on a passed session.

Changes to experiment.py & compute-stats.py
* The session for a run experiment is passed to `api_utils.is_hpc` so that this function can query the now-live master to determine whether that master is running an HPC scheduler. Previous calls to `is_hpc` only accidentally worked because the very first time it was called it brought up a master that happened to run at the same default location as the session `is_hpc` generated by default.
* Formatting
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.

3 participants