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

chore: add tests for agent_state.go queries #8740

Merged
merged 3 commits into from
Jan 24, 2024
Merged

Conversation

stoksc
Copy link
Contributor

@stoksc stoksc commented Jan 24, 2024

Description

Exactly what it says.

Test Plan

  • this change is tests

Commentary (optional)

I removed the RP arg to retrieving agent states since restore is enabled by default for every resource pool now (plus, it was wrong, since I don't think it accounted for implicit default pools).

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

DET-10060

@stoksc stoksc requested a review from a team as a code owner January 24, 2024 15:14
@cla-bot cla-bot bot added the cla-signed label Jan 24, 2024
Copy link

netlify bot commented Jan 24, 2024

Deploy Preview for determined-ui canceled.

Name Link
🔨 Latest commit 8f466bd
🔍 Latest deploy log https://app.netlify.com/sites/determined-ui/deploys/65b13e93caa8750008183a10

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (bf5b1d1) 47.26% compared to head (8f466bd) 47.41%.
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8740      +/-   ##
==========================================
+ Coverage   47.26%   47.41%   +0.15%     
==========================================
  Files        1045     1045              
  Lines      166700   166689      -11     
  Branches     2244     2242       -2     
==========================================
+ Hits        78783    79034     +251     
+ Misses      87759    87497     -262     
  Partials      158      158              
Flag Coverage Δ
backend 41.70% <80.00%> (+0.75%) ⬆️
harness 64.29% <ø> (-0.01%) ⬇️
web 42.57% <ø> (ø)

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

Files Coverage Δ
master/internal/rm/agentrm/agent_state.go 83.98% <80.00%> (+65.46%) ⬆️

... and 7 files with indirect coverage changes

@@ -667,8 +645,7 @@ func (a *agentState) restoreContainersField() error {
}

func clearAgentStates(agentIds []agentID) error {
_, err := db.Bun().NewDelete().Where("agent_id in (?)", agentIds).Exec(context.TODO())

_, err := db.Bun().NewDelete().Model((*agentSnapshot)(nil)).Where("agent_id in (?)", agentIds).Exec(context.TODO())
Copy link
Contributor

Choose a reason for hiding this comment

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

curious did this just not work before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, didn't work at all, i guess.

master/internal/rm/agentrm/agent_state.go Outdated Show resolved Hide resolved
master/internal/rm/agentrm/agent_state.go Outdated Show resolved Hide resolved
log.Panicln(err)
}

err = db.MigrateTestPostgres(pgDB, "file://../../../static/migrations", "up")
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a random note and I don't mean to change anything in this PR but I think the hashicorp video had some fact that tests like always assume you are running from some directory?

I guess my point is we shouldn't need to hard code this since we know what directory we are in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we always run from the package directory, or the directory the tests are in. so we can hardcode it exactly like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really related to this PR and should be a follow up ticket, I guess my point is MigrateTestPostgres shouldn't take a path at all

It should just like traverse its parent directories till it hits master then find the migrations

Would be cool if it was one line too so like

func TestMain(m testing.M) {
    db.TestSetup(t)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's true

@stoksc stoksc merged commit 6db8c06 into main Jan 24, 2024
74 of 85 checks passed
@stoksc stoksc deleted the add-test-for-agent-state branch January 24, 2024 17:26
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.

2 participants