From 8bd80b90bd0231aa7b5ff68602ce4c3adfe249a1 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 8 Oct 2024 14:48:26 -0700 Subject: [PATCH 1/3] Perf optimization in adapter lookup table --- dsc/tests/dsc_discovery.tests.ps1 | 19 +++++++++++++++++-- dsc_lib/src/discovery/command_discovery.rs | 11 +++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/dsc/tests/dsc_discovery.tests.ps1 b/dsc/tests/dsc_discovery.tests.ps1 index fb575888..8c9de5a0 100644 --- a/dsc/tests/dsc_discovery.tests.ps1 +++ b/dsc/tests/dsc_discovery.tests.ps1 @@ -144,10 +144,25 @@ Describe 'tests for resource discovery' { $TestClassResourcePath = Resolve-Path "$PSScriptRoot/../../powershell-adapter/Tests" $env:DSC_RESOURCE_PATH = $null $env:PSModulePath += [System.IO.Path]::PathSeparator + $TestClassResourcePath - dsc resource list -a Microsoft.DSC/PowerShell | Out-Null - "{'Name':'TestClassResource1'}" | dsc -l trace resource get -r 'TestClassResource/TestClassResource' 2> $TestDrive/tracing.txt + # remove adapter lookup table file + Remove-Item -Force -Path $script:lookupTableFilePath -ErrorAction SilentlyContinue + Test-Path $script:lookupTableFilePath -PathType Leaf | Should -BeFalse + + # initial invocation should populate and save adapter lookup table + dsc -l trace resource list -a Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt + "$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Read 0 items into lookup table" + "$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Saving lookup table" + + # second invocation (without an update) should use but not save adapter lookup table + "{'Name':'TestClassResource1'}" | dsc -l trace resource get -r 'TestClassResource/TestClassResource' 2> $TestDrive/tracing.txt "$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Lookup table found resource 'testclassresource/testclassresource' in adapter 'Microsoft.DSC/PowerShell'" + "$TestDrive/tracing.txt" | Should -Not -FileContentMatchExactly "Saving lookup table" + + # third invocation (with an update) should save updated adapter lookup table + dsc -l trace resource list -a Test/TestGroup 2> $TestDrive/tracing.txt + "$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Saving lookup table" + $env:PSModulePath = $oldPSModulePath } diff --git a/dsc_lib/src/discovery/command_discovery.rs b/dsc_lib/src/discovery/command_discovery.rs index 04772ee7..3656514e 100644 --- a/dsc_lib/src/discovery/command_discovery.rs +++ b/dsc_lib/src/discovery/command_discovery.rs @@ -536,15 +536,22 @@ fn add_resources_to_lookup_table(adapted_resources: &BTreeMap) From 3b87bfdc31ff79df6ec01028eae3c136fb682880 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 8 Oct 2024 14:57:32 -0700 Subject: [PATCH 2/3] Perf optimization in adapter lookup table 2 --- dsc_lib/src/discovery/command_discovery.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsc_lib/src/discovery/command_discovery.rs b/dsc_lib/src/discovery/command_discovery.rs index 3656514e..c94abb7d 100644 --- a/dsc_lib/src/discovery/command_discovery.rs +++ b/dsc_lib/src/discovery/command_discovery.rs @@ -541,7 +541,7 @@ fn add_resources_to_lookup_table(adapted_resources: &BTreeMap Date: Fri, 11 Oct 2024 13:53:02 -0700 Subject: [PATCH 3/3] Update dsc/tests/dsc_discovery.tests.ps1 Co-authored-by: Steve Lee --- dsc/tests/dsc_discovery.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsc/tests/dsc_discovery.tests.ps1 b/dsc/tests/dsc_discovery.tests.ps1 index 8c9de5a0..90d349f0 100644 --- a/dsc/tests/dsc_discovery.tests.ps1 +++ b/dsc/tests/dsc_discovery.tests.ps1 @@ -146,7 +146,7 @@ Describe 'tests for resource discovery' { $env:PSModulePath += [System.IO.Path]::PathSeparator + $TestClassResourcePath # remove adapter lookup table file - Remove-Item -Force -Path $script:lookupTableFilePath -ErrorAction SilentlyContinue + Remove-Item -Force -Path $script:lookupTableFilePath -ErrorAction Stop Test-Path $script:lookupTableFilePath -PathType Leaf | Should -BeFalse # initial invocation should populate and save adapter lookup table