From bc5601e849a31dfb100bec7ec64b7abda7f4615b Mon Sep 17 00:00:00 2001 From: JohnMcPMS Date: Wed, 29 Sep 2021 18:31:07 -0700 Subject: [PATCH] Fix REST tests that deadlock, logto file target, and test timeout in script --- src/AppInstallerCLITests/CustomHeader.cpp | 1 + .../Run-TestsInPackage.ps1 | 37 ++++++++++++------- .../TestRestRequestHandler.cpp | 6 ++- src/AppInstallerCLITests/main.cpp | 2 +- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/AppInstallerCLITests/CustomHeader.cpp b/src/AppInstallerCLITests/CustomHeader.cpp index 9741b197c5..673dc8b89c 100644 --- a/src/AppInstallerCLITests/CustomHeader.cpp +++ b/src/AppInstallerCLITests/CustomHeader.cpp @@ -50,6 +50,7 @@ namespace if (!headers.has(customHeader.first) || (utility::conversions::to_utf8string(customHeader.second).compare(utility::conversions::to_utf8string(headers[customHeader.first]))) != 0) { + response.set_body(utf16string{ L"Bad Request" }); response.set_status_code(web::http::status_codes::BadRequest); return pplx::task_from_result(response); } diff --git a/src/AppInstallerCLITests/Run-TestsInPackage.ps1 b/src/AppInstallerCLITests/Run-TestsInPackage.ps1 index f6c950d065..9234c9dab2 100644 --- a/src/AppInstallerCLITests/Run-TestsInPackage.ps1 +++ b/src/AppInstallerCLITests/Run-TestsInPackage.ps1 @@ -46,8 +46,9 @@ function Wait-ForFileClose([string]$Path) { $Local:FileInfo = [System.IO.FileInfo]::new($Path) $Local:SleepCount = 0 + $Local:SleepCountMax = 600 - while ($Local:SleepCount -lt 300) + while ($Local:SleepCount -lt $Local:SleepCountMax) { try { @@ -61,6 +62,11 @@ function Wait-ForFileClose([string]$Path) $Local:SleepCount = $Local:SleepCount + 1 } } + + if ($Local:SleepCount -ge $Local:SleepCountMax) + { + throw "Timed out waiting for file close: $Path" + } } if ([String]::IsNullOrEmpty($BuildRoot)) @@ -133,19 +139,24 @@ Invoke-CommandInDesktopPackage -PackageFamilyName WinGetDevCLI_8wekyb3d8bbwe -Ap if ($ScriptWait) { - Write-Host "Waiting for output files to be closed..." - Start-Sleep 5 - if (![String]::IsNullOrEmpty($LogTarget)) + try { - Wait-ForFileClose $LogTarget - } + Write-Host "Waiting for output files to be closed..." + Start-Sleep 5 + if (![String]::IsNullOrEmpty($LogTarget)) + { + Wait-ForFileClose $LogTarget + } - if (![String]::IsNullOrEmpty($TestResultsTarget)) + if (![String]::IsNullOrEmpty($TestResultsTarget)) + { + Wait-ForFileClose $TestResultsTarget + } + Write-Host "Done" + } + finally { - Wait-ForFileClose $TestResultsTarget + Write-Host "Remove registered package" + Get-AppxPackage WinGetDevCLI | Remove-AppxPackage } - Write-Host "Done" - - Write-Host "Remove registered package" - Get-AppxPackage WinGetDevCLI | Remove-AppxPackage -} \ No newline at end of file +} diff --git a/src/AppInstallerCLITests/TestRestRequestHandler.cpp b/src/AppInstallerCLITests/TestRestRequestHandler.cpp index e9e8f7e7e6..cce63486d0 100644 --- a/src/AppInstallerCLITests/TestRestRequestHandler.cpp +++ b/src/AppInstallerCLITests/TestRestRequestHandler.cpp @@ -13,7 +13,11 @@ std::shared_ptr GetTestRestRequestHandler( pplx::task { web::http::http_response response; - if (!sampleResponseString.empty()) + if (sampleResponseString.empty()) + { + response.set_body(utf16string{}); + } + else { response.set_body(web::json::value::parse(sampleResponseString)); } diff --git a/src/AppInstallerCLITests/main.cpp b/src/AppInstallerCLITests/main.cpp index e7d1b29b0e..b8c79633a2 100644 --- a/src/AppInstallerCLITests/main.cpp +++ b/src/AppInstallerCLITests/main.cpp @@ -73,7 +73,7 @@ int main(int argc, char** argv) else if ("-logto"s == argv[i]) { ++i; - Logging::AddFileLogger(std::string_view{ argv[i] }); + Logging::AddFileLogger(std::filesystem::path{ argv[i] }); } else if ("-tdd"s == argv[i]) {