@@ -12,6 +12,14 @@ function Push-CIPPTest {
1212
1313 Write-Information " Running test $TestId for tenant $TenantFilter "
1414
15+ # Per-process cache of resolved test function commands so that a flat orchestrator
16+ # firing thousands of activities doesn't repeat the module command-table walk
17+ # for every task.
18+ if (-not $script :CIPPTestFunctionLookup ) {
19+ $script :CIPPTestFunctionLookup = [System.Collections.Generic.Dictionary [string , object ]]::new([System.StringComparer ]::OrdinalIgnoreCase)
20+ Write-Information " [CacheInit] CIPPTestFunctionLookup initialized in PID $PID "
21+ }
22+
1523 try {
1624 if ($TestId -like ' CustomScript-*' ) {
1725 $ScriptGuid = $TestId -replace ' ^CustomScript-' , ' '
@@ -23,13 +31,20 @@ function Push-CIPPTest {
2331
2432 $FunctionName = " Invoke-CippTest$TestId "
2533
26- if (-not (Get-Command $FunctionName - Module CIPPTests - ErrorAction SilentlyContinue)) {
34+ if ($script :CIPPTestFunctionLookup.ContainsKey ($FunctionName )) {
35+ Write-Information " [CacheHit] CIPPTestFunctionLookup PID=$PID Key=$FunctionName Size=$ ( $script :CIPPTestFunctionLookup.Count ) "
36+ } else {
37+ Write-Information " [CacheMiss] CIPPTestFunctionLookup PID=$PID Key=$FunctionName Size=$ ( $script :CIPPTestFunctionLookup.Count ) - resolving via Get-Command"
38+ $script :CIPPTestFunctionLookup [$FunctionName ] = Get-Command $FunctionName - Module CIPPTests - ErrorAction SilentlyContinue
39+ }
40+ $TestCommand = $script :CIPPTestFunctionLookup [$FunctionName ]
41+ if (-not $TestCommand ) {
2742 Write-LogMessage - API ' Tests' - tenant $TenantFilter - message " Test function not found: $FunctionName " - sev Error
2843 return @ { testRun = $false }
2944 }
3045
3146 Write-Information " Executing $FunctionName for $TenantFilter "
32- & $FunctionName - Tenant $TenantFilter
47+ & $TestCommand - Tenant $TenantFilter
3348 Write-Host " Returning true, test has run for $tenantFilter "
3449 return @ { testRun = $true }
3550
0 commit comments