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
Only hook to solution events when PMC console is opened while executing ps scripts #1122
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this call ExecuteInitScriptsAsync before every install?
From what I see it just calls it during the first initialization. If an install has already occurred the second solution will not have the init scripts run since the host was not loaded while that solution was opened.
f608e30
to
f92f013
Compare
@emgarten Added code to call ExecuteInitScriptsAsync() for any new install/ uninstall for a solution for which we haven't executed init scripts. Also it will make sure to execute it only once per solution. |
{ | ||
return _solutionManager.IsSolutionOpen ? | ||
_solutionManager.SolutionDirectory : | ||
Environment.GetEnvironmentVariable("USERPROFILE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this just use string.empty instead of userprofile? I don't see this path actually being used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was already there in order to get the target directory so i didn't want to change that. Either way it wouldn't make any difference.
{ | ||
NuGetUIThreadHelper.JoinableTaskFactory.Run(async () => | ||
{ | ||
await ExecuteInitScriptsAsync(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would help to mention that install.ps1/uninstall.ps1 scripts could depend on init.ps1 scripts, and that is why we need to run this first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the comment
@@ -355,6 +367,9 @@ private void UpdateWorkingDirectory() | |||
return; | |||
} | |||
|
|||
// save current solution directory so that we don't execute init scripts for the same solution again. | |||
_currentSolutionDirectory = GetSolutionDirectory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to compare the current and previous directories here inside the lock and noop if they were already run? With the current pattern it looks like all (one) callers need to care about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, updated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address feedback then 🚀
test coverage? adequate today? needs tweaks? Additions? |
@@ -703,6 +703,40 @@ function Test-BatchEventsApi | |||
Assert-True $result | |||
} | |||
|
|||
function Test-ExecuteInitScriptsPerSolution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't verify the change here.
Installing EF will run the init script and it will stay loaded. Also if any other tests install this package they will also run it.
If there are failures in the entityframework.sqlservercompact
install script they won't be caught here, install-package ignores those. So at the end GetInstalledPackages will return everything regardless of what happened for init.ps1 and install.ps1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but i cant find a way to restart the VS itself. Do you know how could we achieve it in our existing infrastructure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To verify that scripts aren't running multiple times you will need to create a package with a custom init.ps1 script. In the init.ps1 script set a failure env var or some other state if it loads and has already been initialized.
From the test verify that the failure state isn't set. Also verify that the init.ps1 was loaded.
You can look at the other init.ps1 tests for examples of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is any way to actually verify that install.ps1 loads all init.ps1 scripts first. Since the PM console has to be open to run E2E tests it should always load these first. You can't test the background host scenario.
The test looks much better ✨ |
42c3506
to
1edbb69
Compare
This change is to improve our PMC performance with respect to DPL and improve below scenarios:
Fixes NuGet/Home#4258
@rrelyea @emgarten @alpaix @mishra14 @rohit21agrawal