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

[nexus] Make project creation unwind safe, add tests #2087

Merged
merged 22 commits into from
Dec 28, 2022

Conversation

smklein
Copy link
Collaborator

@smklein smklein commented Dec 21, 2022

  • Defines undo actions for project creation saga
  • Adds test for the project creation saga

Part of #2052

Comment on lines +98 to +99
let (_authz_project, project) =
sagactx.lookup::<(authz::Project, db::model::Project)>("project")?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let (_authz_project, project) =
sagactx.lookup::<(authz::Project, db::model::Project)>("project")?;
let (.., project) =
sagactx.lookup::<(authz::Project, db::model::Project)>("project")?;

Would this work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They're functionally the same; I was just being explicit about "what is the unused value" in this case since deserialization is particularly important on the lookup function, which is generic based on the type parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, to be pedantic in the context of let binding:

  1. let (.., foo) = ... means "destructure and bind one or more values to the anonymous "...", but only bind the last value to foo"
  2. let (_, foo) = ... means "destructure and bind exactly one value to _, and bind the second value to foo"
  3. let (_unused, foo) = ... means "destructure and bind exactly one value to _unused, and bind the second value to foo"

Technically in cases (1) and (2), since the bind is anonymous, it also goes out of scope, and drop is called immediately on the unnamed values. In contrast, in (3), drop is only called on _unused when it actually goes out of scope.

However, I don't think authz::Project has a drop implementation, hence why this is the same.

So it's not exactly the same, but it's basically the same - I just used this for readability, since the types of values being pulled out of the sagactx.lookup are important to get right, and caller-specified.

@smklein smklein requested a review from plotnick December 27, 2022 19:02
Base automatically changed from vpc-creation-saga-idempotent to main December 27, 2022 20:24
Copy link
Contributor

@plotnick plotnick left a comment

Choose a reason for hiding this comment

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

Left a (non-blocking) security related question, but otherwise looks great, especially the tests; verify_clean_slate is awesome and I'll be stealing that idea in the future.

@smklein smklein merged commit caf7690 into main Dec 28, 2022
@smklein smklein deleted the project-creation-saga-idempotent branch December 28, 2022 20:00
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.

3 participants