-
Notifications
You must be signed in to change notification settings - Fork 199
Add Test Isolation support #2216
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
Open
Drakonian
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
Drakonian:AddTestIsolationSupport2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Test Isolation module for AL-Go for GitHub. | ||
|
|
||
| .DESCRIPTION | ||
| Builds a scriptblock compatible with Run-AlPipeline's -RunTestsInBcContainer | ||
| override. The scriptblock invokes Run-TestsInBcContainer once per declared | ||
| partition (each with its own test runner and codeunit-range filter), plus one | ||
| trailing call under the default runner whose filter excludes every codeunit | ||
| matched by the explicit partitions. | ||
| #> | ||
|
|
||
| function New-PartitionedTestRunnerScriptBlock { | ||
| <# | ||
| .SYNOPSIS | ||
| Build a scriptblock for Run-AlPipeline's -RunTestsInBcContainer hook. | ||
| .DESCRIPTION | ||
| Run-AlPipeline invokes the override once per test app with a hashtable | ||
| of parameters (extensionId, containerName, disabledTests, JUnit/XUnit | ||
| file, AppendTo*ResultFile, auth context, etc.). The returned | ||
| scriptblock loops over the configured partitions and, for each one, | ||
| invokes Run-TestsInBcContainer with the partition's runner id and | ||
| codeunit-range filter. After all partitions, it issues one trailing | ||
| call under defaultRunnerCodeunitId whose -testCodeunitRange is the | ||
| negation of the union of every explicit partition's filter — so every | ||
| test codeunit not matched by an explicit partition runs under the | ||
| default runner exactly once. | ||
|
|
||
| Result-file appending is preserved because we forward the JUnit/XUnit | ||
| file params Run-AlPipeline already configured (AppendTo*ResultFile = $true). | ||
| .PARAMETER Settings | ||
| The testIsolation settings object with `defaultRunnerCodeunitId` and | ||
| `partitions` (array of @{ runnerCodeunitId; codeunits }). Closed over | ||
| by the returned scriptblock. | ||
| .OUTPUTS | ||
| [scriptblock] returning $true if every invocation reported success. | ||
| #> | ||
| Param( | ||
| [Parameter(Mandatory = $true)] | ||
| $Settings | ||
| ) | ||
|
|
||
| $capturedPartitions = @($Settings.partitions) | ||
| $capturedDefaultRunner = [int] $Settings.defaultRunnerCodeunitId | ||
|
|
||
| # Build the negative filter for the trailing default-runner call by | ||
| # collecting every '|'-separated piece from every partition's codeunits | ||
| # filter, prefixing each with '<>' and joining with '&'. Result is a | ||
| # BC integer-field filter expression that matches every codeunit ID NOT | ||
| # covered by an explicit partition. | ||
| $defaultRangeFilter = '' | ||
| if ($capturedPartitions.Count -gt 0) { | ||
| $negatedPieces = @() | ||
| foreach ($p in $capturedPartitions) { | ||
| foreach ($piece in ([string] $p.codeunits).Split('|')) { | ||
| $trimmed = $piece.Trim() | ||
| if ($trimmed) { $negatedPieces += "<>$trimmed" } | ||
| } | ||
| } | ||
| $defaultRangeFilter = $negatedPieces -join '&' | ||
| } | ||
|
|
||
| return { | ||
| Param([Hashtable] $parameters) | ||
|
|
||
| $appId = "$($parameters.extensionId)" | ||
| $allPassed = $true | ||
| $invocations = 0 | ||
|
|
||
| foreach ($p in $capturedPartitions) { | ||
| $call = @{} | ||
| foreach ($k in $parameters.Keys) { $call[$k] = $parameters[$k] } | ||
| $call['testCodeunitRange'] = "$($p.codeunits)" | ||
| $call['testRunnerCodeunitId'] = "$([int] $p.runnerCodeunitId)" | ||
|
|
||
| Write-Host "Running partition runner=$($p.runnerCodeunitId) range='$($p.codeunits)' app=$appId" | ||
| $invocations++ | ||
|
|
||
| $passed = Run-TestsInBcContainer @call | ||
| if (-not $passed) { $allPassed = $false } | ||
| } | ||
|
|
||
| $defaultCall = @{} | ||
| foreach ($k in $parameters.Keys) { $defaultCall[$k] = $parameters[$k] } | ||
| if ($defaultRangeFilter) { $defaultCall['testCodeunitRange'] = $defaultRangeFilter } | ||
| if ($capturedDefaultRunner -gt 0) { $defaultCall['testRunnerCodeunitId'] = "$capturedDefaultRunner" } | ||
| $defaultRunnerDisplay = if ($capturedDefaultRunner -gt 0) { "$capturedDefaultRunner" } else { "BC default" } | ||
|
|
||
| Write-Host "Running default partition runner=$defaultRunnerDisplay range='$defaultRangeFilter' app=$appId" | ||
| $invocations++ | ||
|
|
||
| $passed = Run-TestsInBcContainer @defaultCall | ||
| if (-not $passed) { $allPassed = $false } | ||
|
|
||
| Write-Host "Partitioned test run for app $appId complete. Invocations: $invocations. All passed: $allPassed" | ||
| return $allPassed | ||
| }.GetNewClosure() | ||
| } | ||
|
|
||
| Export-ModuleMember -Function New-PartitionedTestRunnerScriptBlock |
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
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
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
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
Oops, something went wrong.
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.
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.
What if there already is
RunTestsInBcContaineroverride for other purposes?Is there a way to add test isolation w/o using
RunTestsInBcContainer?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.
@mazhelez
Great questions!
I can combine the user scriptblock with the new hashtable
testCodeunitRange+testRunnerCodeunitId. In that case, nothing will be overwritten.In the current design of
bccontainerhelper, I see an alternative, in recent versions,RequiredTestIsolationwas added, and it looks like this can be used as an alternative.https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-requiredtestisolation-property
https://github.com/microsoft/navcontainerhelper/blob/c5fd2aa4e7a36405e50d552a3947102a05931003/AppHandling/Run-TestsInNavContainer.ps1#L532
I think I should look into point 2, I will try testing it and let you know if it works or not.
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.
@mazhelez the main problem with
RequiredTestIsolationthat it will work only for Runtime 16.0 +