Skip to content

Commit e6b0504

Browse files
committed
Refactor: Enhancement of testing tools and code style.
- (Both tools): Avoid using the ternary operator - Refactor all ternary operator expressions with "if-else" snippet. - (Tools/SandboxTest.ps1): Increase memory usage of Sandbox instance - Modifies the memory allocation for the Sandbox instance. - Increase to 1/4 of the total memory size. - This is useful for testing purposes, override default "2GB". - (Tools/YamlCreate.ps1): Change log level - Change `$InformationPreference` to "Continue" - This will NOT suppress `Write-Information` Signed-off-by: Dragon1573 <[email protected]>
1 parent cb072b4 commit e6b0504

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Tools/SandboxTest.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ $script:SandboxWorkingDirectory = Join-Path -Path $script:SandboxDesktopFolder -
9393
$script:SandboxTestDataFolder = Join-Path -Path $script:SandboxDesktopFolder -ChildPath $($script:TestDataFolder | Split-Path -Leaf)
9494
$script:SandboxBootstrapFile = Join-Path -Path $script:SandboxTestDataFolder -ChildPath "$script:ScriptName.ps1"
9595
$script:HostGeoID = (Get-WinHomeLocation).GeoID
96+
# Use quater of the physical memory size for the sandbox, for increasing performance.
97+
$script:PrefferMemorySize = ((Get-WmiObject Win32_PhysicalMemory).Capacity | Measure-Object Capacity -Sum).Sum / (1MB) / 4
98+
if ($script:PrefferMemorySize -le 2048) {
99+
# Physical memory is TOO small! Set the minimum to 2GB.
100+
$script:PrefferMemorySize = 2048 # Minimum of 2GB
101+
}
96102

97103
# Misc
98104
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
@@ -230,14 +236,13 @@ function Get-RemoteContent {
230236
)
231237
Write-Debug "Attempting to fetch content from $URL"
232238
# Check if the URL is valid before trying to download
233-
# If the URL is null, return a status code of 400
239+
# Check if URL is empty
234240
if ([String]::IsNullOrWhiteSpace($URL)) {
235241
$response = @{ StatusCode = 400 }
236242
} else {
237243
# Try to fetch headers from the URL
238244
$response = Invoke-WebRequest -Proxy $Proxy -Uri $URL -Method Head -ErrorAction SilentlyContinue
239245
}
240-
241246
if ($response.StatusCode -ne 200) {
242247
Write-Debug "Fetching remote content from $URL returned status code $($response.StatusCode)"
243248
return $null
@@ -255,7 +260,6 @@ function Get-RemoteContent {
255260
} else {
256261
$script:CleanupPaths += @()
257262
}
258-
259263
try {
260264
$downloadTask = $script:HttpClient.GetByteArrayAsync($URL)
261265
[System.IO.File]::WriteAllBytes($localfile.FullName, $downloadTask.Result)
@@ -867,8 +871,9 @@ Write-Verbose 'Creating WSB file for launching the sandbox'
867871
</MappedFolder>
868872
</MappedFolders>
869873
<LogonCommand>
870-
<Command>PowerShell Start-Process PowerShell -WindowStyle Maximized -WorkingDirectory '$($script:SandboxWorkingDirectory)' -ArgumentList '-ExecutionPolicy Bypass -NoExit -NoLogo -File $($script:SandboxBootstrapFile)'</Command>
874+
<Command>PowerShell Start-Process PowerShell -WindowStyle Maximized -WorkingDirectory '$($script:SandboxWorkingDirectory)' -ArgumentList '-ExecutionPolicy Bypass -NoExit -NoLogo -File $($script:SandboxBootstrapFile)'</Command>
871875
</LogonCommand>
876+
<memoryInMB>$script:PrefferMemorySize</memoryInMB>
872877
</Configuration>
873878
"@ | Out-File -FilePath $script:ConfigurationFile
874879

Tools/YamlCreate.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Param
4444
[string] $Proxy = $null
4545
)
4646
$ProgressPreference = 'SilentlyContinue'
47+
$InformationPreference = 'Continue'
4748

4849
if (!$Proxy) {
4950
# Try inspect the system-level proxy settings by visiting GitHub RESTful API Endpoint and extract proxy settings from it.

0 commit comments

Comments
 (0)