Adjust Test Watcher Timeout for Test Collections (#83746)
authorIvan Diaz Sanchez <ivdiazsa@microsoft.com>
Thu, 23 Mar 2023 18:11:55 +0000 (11:11 -0700)
committerGitHub <noreply@github.com>
Thu, 23 Mar 2023 18:11:55 +0000 (11:11 -0700)
src/native/watchdog/watchdog.cpp
src/tests/Common/CLRTest.Execute.Bash.targets
src/tests/Common/CLRTest.Execute.Batch.targets
src/tests/Common/helixpublishwitharcade.proj

index fec9674cd28366befdcf79bb8b2c3e099d950b38..2ab508a5fb53c84a884089d9420d2207de96be5c 100644 (file)
@@ -35,8 +35,11 @@ int main(const int argc, const char *argv[])
         return EXIT_FAILURE;
     }
 
-    const long timeout_ms = strtol(argv[1], nullptr, 10);
-    int exit_code = run_timed_process(timeout_ms, argc-2, &argv[2]);
+    // Due to how Helix test environment variables are set, we have to receive
+    // the raw timeout value in minutes. Then we convert it to milliseconds when
+    // calling run_timed_process().
+    const long timeout_mins = strtol(argv[1], nullptr, 10);
+    int exit_code = run_timed_process(timeout_mins * 60000L, argc-2, &argv[2]);
 
     printf("App Exit Code: %d\n", exit_code);
     return exit_code;
index 0623040dc12d801ae72476a2a7ea8126bd4c1f39..89e893539e69da9d1dc56ef9505ade62ee47a1a3 100644 (file)
@@ -290,7 +290,7 @@ fi
       </PropertyGroup>
       <PropertyGroup>
       <CLRTestRunFile Condition="'$(CLRTestIsHosted)'=='true'">"$CORE_ROOT/corerun" $(CoreRunArgs)  ${__DotEnvArg}</CLRTestRunFile>
-      <WatcherRunFile>"$CORE_ROOT/watchdog" $_WatcherTimeoutMilliseconds</WatcherRunFile>
+      <WatcherRunFile>"$CORE_ROOT/watchdog" $_WatcherTimeoutMins</WatcherRunFile>
 
       <!-- Note that this overwrites CLRTestBashPreCommands rather than adding to it. -->
       <CLRTestBashPreCommands Condition="'$(CLRTestKind)' == 'BuildAndRun' and '$(TargetArchitecture)' == 'wasm'"><![CDATA[
@@ -549,12 +549,19 @@ ReleaseLock()
 cd "$%28dirname "${BASH_SOURCE[0]}")"
 LockFile="lock"
 _RunWithWatcher=0
-_WatcherTimeoutMilliseconds=600000
+_WatcherTimeoutMins=10
 
-if [[ ! -z "$__TestTimeout" ]]%3B then
-    _WatcherTimeoutMilliseconds=$__TestTimeout
+if [[ ! -z "$__TestCollectionTimeoutMins" ]]%3B then
+    _WatcherTimeoutMins=$__TestCollectionTimeoutMins
 fi
 
+# The watcher needs a bit of time to start up, capture dumps, clean up, and so on.
+# Because of this, we pass a smaller timeout than the test collection one.
+# For simplicity purposes, we will assume there are no work items with just
+# a one-minute max timeout.
+if (( $_WatcherTimeoutMins > 1 ))%3B then
+    _WatcherTimeoutMins="%24((_WatcherTimeoutMins-1))"
+fi
 
 # The __TestEnv variable may be used to specify a script to source before the test.
 if [ -n "$__TestEnv" ]%3B then
index 605bc77b6963c0b70a07e9cbaa1cd55c6e4301db..7ae089a0ae72ed045f566cb5155a671713688ce6 100644 (file)
@@ -298,7 +298,7 @@ if defined DoLink (
       </PropertyGroup>
       <PropertyGroup>
       <CLRTestRunFile Condition="'$(CLRTestIsHosted)'=='true'">"%CORE_ROOT%\corerun.exe" $(CoreRunArgs) %__DotEnvArg%</CLRTestRunFile>
-      <WatcherRunFile>"%CORE_ROOT%\watchdog.exe" %_WatcherTimeoutMilliseconds%</WatcherRunFile>
+      <WatcherRunFile>"%CORE_ROOT%\watchdog.exe" %_WatcherTimeoutMins%</WatcherRunFile>
 
       <BatchCopyCoreShimLocalCmds Condition="'$(CLRTestScriptLocalCoreShim)' == 'true'"><![CDATA[
 REM Local CoreShim requested - see MSBuild property 'CLRTestScriptLocalCoreShim'
@@ -439,10 +439,18 @@ set "lockFolder=%~dp0\lock"
 pushd %~dp0
 set "scriptPath=%~dp0"
 set /A _RunWithWatcher=0
-set _WatcherTimeoutMilliseconds=600000
+set /A _WatcherTimeoutMins=10
 
-IF NOT "%__TestTimeout%"=="" (
-    set _WatcherTimeoutMilliseconds=%__TestTimeout%
+IF NOT "%__TestCollectionTimeoutMins%"=="" (
+    set /A _WatcherTimeoutMins=%__TestCollectionTimeoutMins%
+)
+
+REM The watcher needs a bit of time to start up, capture dumps, clean up, and so on.
+REM Because of this, we pass a smaller timeout than the test collection one.
+REM For simplicity purposes, we will assume there are no work items with just
+REM a one-minute max timeout.
+IF %_WatcherTimeoutMins% GTR 1 (
+    set /A _WatcherTimeoutMins-=1
 )
 
 $(BatchCLRTestArgPrep)
index 1bacf4b9313a11c96931d2dd70024cf6012fbfba..2864f16cce369af3791bfcaadc42e685b735cdbd 100644 (file)
     <HelixPreCommand Include="set CLRCustomTestLauncher=%HELIX_CORRELATION_PAYLOAD%\nativeaottest.cmd" Condition=" '$(NativeAotTest)' == 'true' " />
     <HelixPreCommand Include="set __TestEnv=%HELIX_WORKITEM_PAYLOAD%\$(TestEnvFileName)" />
     <HelixPreCommand Include="set __TestTimeout=$(TimeoutPerTestInMilliseconds)" Condition=" '$(TimeoutPerTestInMilliseconds)' != '' " />
+    <HelixPreCommand Include="set __TestCollectionTimeoutMins=$(TimeoutPerTestCollectionInMinutes)" Condition=" '$(TimeoutPerTestCollectionInMinutes)' != '' " />
     <HelixPreCommand Include="set __CollectDumps=1" />
     <HelixPreCommand Include="set __CrashDumpFolder=%HELIX_DUMP_FOLDER%" />
     <HelixPreCommand Include="set __TestArchitecture=$(TargetArchitecture)" />
     <HelixPreCommand Include="export CLRCustomTestLauncher=$HELIX_CORRELATION_PAYLOAD/nativeaottest.sh" Condition=" '$(NativeAotTest)' == 'true' " />
     <HelixPreCommand Include="export __TestEnv=$HELIX_WORKITEM_PAYLOAD/$(TestEnvFileName)" />
     <HelixPreCommand Include="export __TestTimeout=$(TimeoutPerTestInMilliseconds)" Condition=" '$(TimeoutPerTestInMilliseconds)' != '' " />
+    <HelixPreCommand Include="export __TestCollectionTimeoutMins=$(TimeoutPerTestCollectionInMinutes)" Condition=" '$(TimeoutPerTestCollectionInMinutes)' != '' " />
     <HelixPreCommand Include="export __CollectDumps=1" />
     <HelixPreCommand Include="export __CrashDumpFolder=$HELIX_DUMP_FOLDER" />
     <HelixPreCommand Include="set __TestArchitecture=$(TargetArchitecture)" />