fix(test): test delete Windows registry accidently - #4918
Conversation
a758fde to
c4635ae
Compare
| static REGISTRY_LOCK: Mutex<()> = Mutex::new(()); | ||
| impl Drop for RegistryGuard { | ||
| fn drop(&mut self) { | ||
| for (id, prev) in self.saved.iter().rev() { |
There was a problem hiding this comment.
I guess since we're trying to remove the whole test subtree all together, no need for settting them empty again here?
|
Another thing here is, can we make code format coming along with commits instead of doing formatting in the end commit here. |
This comment has been minimized.
This comment has been minimized.
9be4399 to
360e048
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
360e048 to
dcd1d78
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| } | ||
| Ok(()) if !no_modify_path => { | ||
| info!("removing cargo bin directory `{cargo_bin_display}` from $PATH"); | ||
| do_remove_from_path(process)?; |
There was a problem hiding this comment.
Moving do_remove_from_programs() out of this match{} is a separate change and has nothing to do with this refactoring commit.
Consider spitting this into a refactoring commit (that puts do_remove_from_programs() directly below this line) first, and a breaking change commit (moving the above call out of the match{} block) after that.
| } | ||
|
|
||
| #[cfg(windows)] | ||
| do_add_to_programs(cfg.process)?; |
| id, | ||
| prev: id.get()?, | ||
| }) | ||
| fn registry_sub_key_path(sub_key: &str, process: &Process) -> String { |
There was a problem hiding this comment.
Nit: This should be converted into a Windows-only method of the Process type.
|
|
||
| #[cfg(not(any(test, feature = "test")))] | ||
| fn registry_sub_key_path(sub_key: &str, _process: &Process) -> String { | ||
| sub_key.to_owned() |
There was a problem hiding this comment.
There doesn't seem to be a need for this function.
| impl RegistryValueId { | ||
| pub fn get(&self) -> Result<Option<Value>> { | ||
| let sub_key = CURRENT_USER.create(self.sub_key)?; | ||
| fn resolved_sub_key(&self, uuid: Option<&str>) -> windows_registry::Result<Key> { |
There was a problem hiding this comment.
Suggest inlining this function.
| impl RegistryValueId { | ||
| pub fn get(&self) -> Result<Option<Value>> { | ||
| let sub_key = CURRENT_USER.create(self.sub_key)?; | ||
| fn resolved_sub_key(&self, uuid: Option<&str>) -> windows_registry::Result<Key> { |
There was a problem hiding this comment.
It seems that in every test case involving registry access, a UUID is needed anyways, if that is indeed true, I don't see a reason to pass Option<> here.
| pub struct RegistryGuard { | ||
| uuid: String, | ||
| saved: Vec<(&'static RegistryValueId, Option<Value>)>, | ||
| } |
There was a problem hiding this comment.
If the analysis in d303f39#r3721131249 is correct, then we don't need a registry guard at all.
| id, | ||
| prev: id.get()?, | ||
| }) | ||
| fn registry_sub_key_path(sub_key: &str, process: &Process) -> String { |
There was a problem hiding this comment.
When we are running tests, new registry keys and all its children should be created as volatile, so that we won't leave unintended garbage entries in the developer's machine (thanks, @Cloud0310).
| test_root_dir: PathBuf, | ||
| /// Per-test Windows registry UUID. | ||
| #[cfg(windows)] | ||
| pub test_registry_uuid: Option<String>, |
There was a problem hiding this comment.
It feels like this (01182b7) should be squashed into one of the previous commits; your goal should be that each commit would still be able to pass all the tests.
There was a problem hiding this comment.
@baka-gourd I think this looks quite interesting but would require more work before it can be merged.
Three general principles of our committing style:
- Each commit should do one single thing, whether that is refactoring, introducing a breaking change, or adding a new feature.
- Each commit should ensure that all test cases are passing. If running all tests is not practical in your local environment, you should have run at least all related tests and have made sure that they are passing.
- When a commit indicates a behavioral change that might cause some tests to fail, you should update those influenced tests in the same commit so that they pass again.
6366e7f to
78a2fde
Compare
fix #4915
This PR is intended to fix the issue mentioned in the ticket regarding the accidental deletion of existing registry entries. However, while investigating the problem, we also discovered a concurrency issue in RegistryGuard, so the scope of the fix is quite extensive.