test: import the module once per run - #40
Merged
Merged
Conversation
Every one of the 111 test files forced a fresh import in its BeforeAll and removed the module in its AfterAll, at about 190 ms each: a quarter of the run on a workstation. A file now imports the module only if it is not loaded and leaves it loaded. State one file leaves behind is visible to the next, which the shuffled CI run catches with a seed to replay; the contract suite still forces a fresh import, because it asserts what a freshly imported module looks like. Measured: 80 seconds to about 65 on PowerShell 7 across three shuffled seeds, 150 to 133 on Windows PowerShell 5.1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item 7 from the optimisation list, the last one.
What was measured
Import-Module -Force, coldImport-Module -Force, warmImport-Modulewhen already loadedEvery one of the 111 test files forced a warm import in
BeforeAlland removed the module inAfterAll: about 21 seconds of an 80-second run.What changed
Each file now imports the module only if it is not already loaded, and none removes it afterwards.
Module.Contract.Tests.ps1keeps its forced import, because it asserts what a freshly imported module looks like, including that no provider is active.The trade
State one file leaves in the module is now visible to the next. Fourteen suites write a provider connection into module scope, and several connect through the real command. That is exactly the kind of dependency the shuffled CI run from #35 exists to catch: a test that only passes after a fresh import, or only before another file connected, fails there with a seed to replay. Three shuffled seeds locally and the CI runs on this PR all pass, so no such dependency exists today, and the shuffle is what keeps it that way.
Verification