8000 Test-ModuleManifest should not load unnecessary modules by chunqingchen · Pull Request #4541 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Test-ModuleManifest should not load unnecessary modules #4541

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

Merged
merged 3 commits into from
Aug 28, 2017

Conversation

chunqingchen
Copy link
Contributor

Fix issue #4533

Summary of the issue:

Test-ModuleManifest is loading unnecessary modules

Fix:
Change the recursive loading flag from 'true' to 'false'

/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/

Copy link
Member

Choose a reason for hiding this comment

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

Something is wrong with your change in this file. The diff is messed up.

Copy link
Member
@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

Please fix the change in TestModuleManifestCommand.cs

@chunqingchen
Copy link
Contributor Author

@daxian-dbw code file format fixed

@daxian-dbw daxian-dbw dismissed their stale review August 11, 2017 14:55

New commit was pushed.

@daxian-dbw
Copy link
Member

@chunqingchen Thanks! Will continue the review.

Copy link
Member
@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

The test assert folder testmodulerunspace should be moved to engine\Module\assets folder. Create assets folder if it doesn't exist.
All test assets should follow this pattern, take a look at the test\powershell\engine\Help\assets folder as an example.


Describe "Test-ModuleManifest Performance bug followup" -tags "CI" {

$TestModulesFolder= 'testmodulerunspace'
Copy link
Member

Choose a reason for hiding this comment

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

Setup should go in BeforeAll block.

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


#clen up the test module
Remove-Item $UserModulesPath\ModuleWithDependencies2 -Recurse -Force -ErrorAction Ignore
Remove-Item $UserModulesPath\NestedRequiredModule1 -Recurse -Force -ErrorAction Ignore
Copy link
Member

Choose a reason for hiding this comment

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

Cleanup should go in AfterAll block.

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


$TestModulesFolder= 'testmodulerunspace'
$TestModulesPath = Join-path $PSScriptRoot $TestModulesFolder
$script:UserModulesPath = Join-path [System.AppDomain]::CurrentDomain.BaseDirectory '\Modules'
Copy link
Member

Choose a reason for hiding this comment

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

This is not UserModulePath. If you want to use the Module folder that's next to powershell.exe, then replace ...currentdomain.basedirectory with $pshome.

And also, there is no need to use $script: for this variable.

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



# Install the Test Module
Copy-Item $TestModulesPath\* $UserModulesPath -Recurse -Force
Copy link
Member

Choose a reason for hiding this comment

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

Setup should go in BeforeAll

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

catch
{
throw $_
}
Copy link
Member

Choose a reason for hiding this comment

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

this catch doesn't seem necessary -- if it just rethrows the exception, why would you catch it?

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

throw $_
}

$verbose = $job.ChildJobs[0].Verbose.ReadAll()
Copy link
Member

Choose a reason for hiding this comment

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

Don't you need to wait for the job to finish to read all verbose message?

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

}

$verbose = $job.ChildJobs[0].Verbose.ReadAll()
$verbose.Count -le 50 | should be true
Copy link
Member

Choose a reason for hiding this comment

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

What does the number 50 mean here? Why do you think -le 50 means it doesn't load unnecessary modules?

Copy link
Contributor Author
@chunqingchen chunqingchen Aug 15, 2017

Choose a reason for hiding this comment

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

Prior to the fix test-modulemanifest will load all the modules in the $pshome, creating a far more big verbose list.

50 is a random small number that small enough to make sure the issue doesn't repro.

It can't be fixed as well since the verbose message contains other information that may vary.

I've changed the number to an even smaller number 15.

# Generated by: manikb
#
# Generated on: 10/29/2015
#
Copy link
Member

Choose a reason for hiding this comment

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

Can you please remove all comments in this file? They make it hard to see what fields are actually used.

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

#
# Generated on: 4/14/2015
#

Copy link
Member

Choose a reason for hiding this comment

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

Same here, please remove all comments.

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

@@ -0,0 +1 @@
function Get-ModuleWithDependencies2 { Get-Date }
Copy link
Member

Choose a reason for hiding this comment

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

I don't see this file used in ModuleWithDependencies2.psd1, is it really needed?

Copy link
Contributor Author
@chunqingchen chunqingchen Aug 15, 2017

Choose a reason for hiding this comment

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

deleted

@@ -216,7 +216,7 @@ protected override void ProcessRecord()
{
foreach (ModuleSpecification moduleListModule in moduleListModules)
{
var modules = GetModule(new[] { moduleListModule.Name }, true, true);
var modules = GetModule(new[] { moduleListModule.Name }, false, true);
Copy link
Member

Choose a reason for hiding this comment

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

Use named parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a sync fix of the bug fix under windows bug 7980238.
so I would prefer to keep the code the way the original fix was

Copy link
Member

Choose a reason for hiding this comment

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

I think they should be made named parameters (as well as the other GetModule call in the same file). We don't make any changes to the original fix when re-submitting it for the sake of less churn. Now when making changes to the Github code base, we want the changes to follow best practices.

Copy link
Member

Choose a reason for hiding this comment

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

The comment regarding named parameters is not resolved yet.

@@ -217,3 +217,37 @@ Describe "Tests for circular references in required modules" -tags "CI" {
{ TestImportModule $false $false $true } | ShouldBeErrorId "Modules_InvalidManifest,Microsoft.PowerShell.Commands.ImportModuleCommand"
}
}

Describe "Test-ModuleManifest Performance bug followup" -tags "CI" {
Copy link
Member

Choose a reason for hiding this comment

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

Please fix indentation

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


$TestModulesFolder= 'testmodulerunspace'
$TestModulesPath = Join-path $PSScriptRoot $TestModulesFolder
$script:UserModulesPath = Join-path [System.AppDomain]::CurrentDomain.BaseDirectory '\Modules'
Copy link
Member

Choose a reason for hiding this comment

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

Do not need \Modules, Modules should be sufficient

@@ -0,0 +1 @@
function Get-NestedRequiredModule1 { Get-Date }
Copy link
Member

Choose a reason for hiding this comment

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

Add end of line.

@@ -0,0 +1 @@
function Get-ModuleWithDependencies2 { Get-Date }
Copy link
Member

Choose a reason for hiding this comment

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

Add end of line.

BeforeAll {
$TestModulesFolder= 'testmodulerunspace'
$TestModulesPath = Join-path "$PSScriptRoot\assets" $TestModulesFolder
$UserModulesPath = Join-path "$pshome\Modules"
Copy link
Member

Choose a reason for hiding this comment

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

Join-path "$pshome\Modules"

Does this call to Join-Path even work?

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

$job = start-job -name "job1" -ScriptBlock {test-modulemanifest "$using:UserModulesPath\ModuleWithDependencies2\2.0\ModuleWithDependencies2.psd1" -verbose} | Wait-Job

$verbose = $job.ChildJobs[0].Verbose.ReadAll()
$verbose.Count -le 15 | should be true
Copy link
Member

Choose a reason for hiding this comment

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

You should use BeLessThan here. See https://github.com/pester/Pester/wiki/Should#belessthan

Copy link
Member

Choose a reason for hiding this comment

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

And please put your rational about using the number '15' in comments here, so that people look at this code later will understand it.

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

# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''
Copy link
Member

Choose a reason for hiding this comment

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

There are so many comments in this file that you haven't deleted yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i thought you mean the comments added in addition to the auto generated ones. resolved.

# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''
Copy link
Member

Choose a reason for hiding this comment

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

ditto

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

@chunqingchen
Copy link
Contributor Author

@daxian-dbw @adityapatwardhan your comments are resolved

@@ -183,7 +183,7 @@ protected override void ProcessRecord()
{
foreach (ModuleSpecification requiredModule in requiredModules)
{
var modules = GetModule(new[] { requiredModule.Name }, false, true);
var modules = GetModule(new[] { requiredModule.Name }, all: false, frefresh: true);
Copy link
Member

Choose a reason for hiding this comment

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

typo frefresh -> refresh

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, thank you

97A7
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

Describe "Test-ModuleManifest Performance bug followup" -tags "CI" {
BeforeAll {
$TestModulesFolder= 'testmodulerunspace'
$TestModulesPath = Join-path "$PSScriptRoot\assets" $TestModulesFolder
Copy link
Member

Choose a reason for hiding this comment

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

This can be

$TestModulesPath = Join-path -Path "$PSScriptRoot\assets" -ChildPath $TestModulesFolder -AdditionalChildPath 'testmodulerunspace'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't get it. Any good besides it putting two lines into one? It also throws error once I copied it. Can we just skip this comment?

NestedModules = @('NestedRequiredModule1')

# Functions to export from this module
FunctionsToExport = '*'
Copy link
Member

Choose a reason for hiding this comment

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

This should be FunctionsToExport = @()

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, thanks

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

FunctionsToExport = '*'

# Cmdlets to export from this module
CmdletsToExport = '*'
Copy link
Member

Choose a reason for hiding this comment

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

This should be CmdletsToExport = @()

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

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

VariablesToExport = '*'

# Aliases to export from this module
AliasesToExport = '*'
Copy link
Member

Choose a reason for hiding this comment

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

This should be AliasesToExport = @()

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

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

NestedModules = @('NestedRequiredModule1.psm1')

# Functions to export from this module
FunctionsToExport = '*'
Copy link
Member

Choose a reason for hiding this comment

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

Same comments as the other module.

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

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


AfterAll {
#clean up the test module
Remove-Item $UserModulesPath\ModuleWithDependencies2 -Recurse -Force -ErrorAction Ignore
Copy link
Member

Choose a reason for hiding this comment

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

Should be -ErrorAction SilentlyContinue

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, thanks

AfterAll {
#clean up the test module
Remove-Item $UserModulesPath\ModuleWithDependencies2 -Recurse -Force -ErrorAction Ignore
Remove-Item $UserModulesPath\NestedRequiredModule1 -Recurse -Force -ErrorAction Ignore
Copy link
Member

Choose a reason for hiding this comment

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

Should be 10000 -ErrorAction SilentlyContinue

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

@@ -0,0 +1 @@
function Get-NestedRequiredModule1 { Get-Date }
Copy link
Member

Choose a reason for hiding this comment

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

missing new line at end of file.

@daxian-dbw daxian-dbw self-assigned this Aug 28, 2017
@daxian-dbw daxian-dbw merged commit fe51fb7 into PowerShell:master Aug 28, 2017
@daxian-dbw daxian-dbw changed the title Test-ModuleManifest should not load unnessary modules Test-ModuleManifest should not load unnecessary modules Aug 28, 2017
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.

5 participants
0