Skip to content

Commit aef12ba

Browse files
marcpopMSFTam11dsplaisted
authored
Enable test timeout dump collection (#44730)
Co-authored-by: Adeel Mujahid <[email protected]> Co-authored-by: Daniel Plaisted <[email protected]>
1 parent e2b4f9e commit aef12ba

File tree

5 files changed

+37
-38
lines changed

5 files changed

+37
-38
lines changed

src/Cli/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ public ForwardingAppImplementation WithEnvironmentVariable(string name, string v
9393
return this;
9494
}
9595

96-
private string GetHostExeName()
97-
{
98-
// Should instead make this a full path to dotnet
99-
return Environment.ProcessPath;
100-
}
96+
private string GetHostExeName() => new Muxer().MuxerPath;
10197
}
10298
}
10399

src/Cli/Microsoft.DotNet.Cli.Utils/Muxer.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,31 @@ public string MuxerPath
3434

3535
public Muxer()
3636
{
37+
// Best-effort search for muxer.
38+
// SDK sets DOTNET_HOST_PATH as absolute path to current dotnet executable
3739
#if NET6_0_OR_GREATER
38-
_muxerPath = Environment.ProcessPath;
40+
string processPath = Environment.ProcessPath;
3941
#else
40-
_muxerPath = Process.GetCurrentProcess().MainModule.FileName;
42+
string processPath = Process.GetCurrentProcess().MainModule.FileName;
4143
#endif
44+
45+
// The current process should be dotnet in most normal scenarios except when dotnet.dll is loaded in a custom host like the testhost
46+
if (!Path.GetFileNameWithoutExtension(processPath).Equals("dotnet", StringComparison.OrdinalIgnoreCase))
47+
{
48+
// SDK sets DOTNET_HOST_PATH as absolute path to current dotnet executable
49+
processPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH");
50+
if (processPath is null)
51+
{
52+
// fallback to DOTNET_ROOT which typically holds some dotnet executable
53+
var root = Environment.GetEnvironmentVariable("DOTNET_ROOT");
54+
if (root is not null)
55+
{
56+
processPath = Path.Combine(root, $"dotnet{Constants.ExeSuffix}");
57+
}
58+
}
59+
}
60+
61+
_muxerPath = processPath;
4262
}
4363

4464
public static string GetDataFromAppDomain(string propertyName)

test/ArgumentForwarding.Tests/ArgumentForwardingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private string[] EscapeAndEvaluateArgumentString(string[] rawEvaluatedArgument)
165165

166166
Console.WriteLine($"STDERR: {commandResult.StdErr}");
167167

168-
commandResult.ExitCode.Should().Be(0);
168+
commandResult.ExitCode.Should().Be(0, $"STDOUT: {commandResult.StdOut} STDERR: {commandResult.StdErr}");
169169

170170
return ParseReflectorOutput(commandResult.StdOut);
171171
}

test/HelixTasks/AssemblyScheduler.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,18 @@ private sealed class AssemblyInfoBuilder
6969
private readonly StringBuilder _builder = new();
7070
private readonly string _assemblyPath;
7171
private readonly int _methodLimit;
72-
private readonly bool _netFramework;
7372
private int _currentId;
7473
private List<TypeInfo> _currentTypeInfoList = new();
7574

76-
private AssemblyInfoBuilder(string assemblyPath, int methodLimit, bool netFramework = false)
75+
private AssemblyInfoBuilder(string assemblyPath, int methodLimit)
7776
{
7877
_assemblyPath = assemblyPath;
7978
_methodLimit = methodLimit;
80-
_netFramework = netFramework;
8179
}
8280

8381
internal static void Build(string assemblyPath, int methodLimit, List<TypeInfo> typeInfoList, out List<Partition> partitionList, out List<AssemblyPartitionInfo> assemblyInfoList, bool netFramework = false)
8482
{
85-
var builder = new AssemblyInfoBuilder(assemblyPath, methodLimit, netFramework);
83+
var builder = new AssemblyInfoBuilder(assemblyPath, methodLimit);
8684
builder.Build(typeInfoList);
8785
partitionList = builder._partitionList;
8886
assemblyInfoList = builder._assemblyInfoList;
@@ -95,19 +93,13 @@ private void Build(List<TypeInfo> typeInfoList)
9593
foreach (var typeInfo in typeInfoList)
9694
{
9795
_currentTypeInfoList.Add(typeInfo);
98-
if (_netFramework)
99-
{
100-
if (_builder.Length > 0)
101-
{
102-
_builder.Append("|");
103-
}
104-
_builder.Append($@"{typeInfo.FullName}");
10596

106-
}
107-
else
97+
if (_builder.Length > 0)
10898
{
109-
_builder.Append($@"-class ""{typeInfo.FullName}"" ");
99+
_builder.Append("|");
110100
}
101+
_builder.Append($@"{typeInfo.FullName}");
102+
111103
CheckForPartitionLimit(done: false);
112104
}
113105

test/HelixTasks/SDKCustomCreateXUnitWorkItemsWithTestExclusion.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,9 @@ private async Task<List<ITaskItem>> PrepareWorkItem(ITaskItem xunitProject)
121121
// These tests have to be executed slightly differently and we give them a different Identity so ADO can tell them apart
122122
var runtimeTargetFrameworkParsed = NuGetFramework.Parse(runtimeTargetFramework);
123123
var testIdentityDifferentiator = "";
124-
bool netFramework = false;
125124
if (runtimeTargetFrameworkParsed.Framework == ".NETFramework")
126125
{
127126
testIdentityDifferentiator = ".netfx";
128-
netFramework = true;
129127
}
130128
else if (runtimeTargetFrameworkParsed.Framework != ".NETCoreApp")
131129
{
@@ -134,9 +132,9 @@ private async Task<List<ITaskItem>> PrepareWorkItem(ITaskItem xunitProject)
134132

135133
// On mac due to https://github.com/dotnet/sdk/issues/3923, we run against workitem directory
136134
// but on Windows, if we running against working item diretory, we would hit long path.
137-
string testExecutionDirectory = netFramework ? "-e DOTNET_SDK_TEST_EXECUTION_DIRECTORY=%TestExecutionDirectory%" : IsPosixShell ? "-testExecutionDirectory $TestExecutionDirectory" : "-testExecutionDirectory %TestExecutionDirectory%";
135+
string testExecutionDirectory = IsPosixShell ? "-e DOTNET_SDK_TEST_EXECUTION_DIRECTORY=$TestExecutionDirectory" : "-e DOTNET_SDK_TEST_EXECUTION_DIRECTORY=%TestExecutionDirectory%";
138136

139-
string msbuildAdditionalSdkResolverFolder = netFramework ? "-e DOTNET_SDK_TEST_MSBUILDSDKRESOLVER_FOLDER=%HELIX_CORRELATION_PAYLOAD%\\r" : IsPosixShell ? "" : "-msbuildAdditionalSdkResolverFolder %HELIX_CORRELATION_PAYLOAD%\\r";
137+
string msbuildAdditionalSdkResolverFolder = IsPosixShell ? "" : "-e DOTNET_SDK_TEST_MSBUILDSDKRESOLVER_FOLDER=%HELIX_CORRELATION_PAYLOAD%\\r";
140138

141139
if (ExcludeAdditionalParameters.Equals("true"))
142140
{
@@ -145,23 +143,16 @@ private async Task<List<ITaskItem>> PrepareWorkItem(ITaskItem xunitProject)
145143
}
146144

147145
var scheduler = new AssemblyScheduler(methodLimit: !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TestFullMSBuild")) ? 32 : 16);
148-
var assemblyPartitionInfos = scheduler.Schedule(targetPath, netFramework: netFramework);
146+
var assemblyPartitionInfos = scheduler.Schedule(targetPath);
149147

150148
var partitionedWorkItem = new List<ITaskItem>();
151149
foreach (var assemblyPartitionInfo in assemblyPartitionInfos)
152150
{
153151
string command;
154-
if (netFramework)
155-
{
156-
var testFilter = string.IsNullOrEmpty(assemblyPartitionInfo.ClassListArgumentString) ? "" : $"--filter \"{assemblyPartitionInfo.ClassListArgumentString}\"";
157-
command = $"{driver} test {assemblyName} -e HELIX_WORK_ITEM_TIMEOUT={timeout} {testExecutionDirectory} {msbuildAdditionalSdkResolverFolder} " +
158-
$"{(XUnitArguments != null ? " " + XUnitArguments : "")} --results-directory .\\ --logger trx {testFilter}";
159-
}
160-
else
161-
{
162-
command = $"{driver} exec {assemblyName} -e HELIX_WORK_ITEM_TIMEOUT={timeout} {testExecutionDirectory} {msbuildAdditionalSdkResolverFolder} " +
163-
$"{(XUnitArguments != null ? " " + XUnitArguments : "")} -xml testResults.xml {assemblyPartitionInfo.ClassListArgumentString} {arguments}";
164-
}
152+
153+
var testFilter = string.IsNullOrEmpty(assemblyPartitionInfo.ClassListArgumentString) ? "" : $"--filter \"{assemblyPartitionInfo.ClassListArgumentString}\"";
154+
command = $"{driver} test {assemblyName} -e HELIX_WORK_ITEM_TIMEOUT={timeout} {testExecutionDirectory} {msbuildAdditionalSdkResolverFolder} " +
155+
$"{(XUnitArguments != null ? " " + XUnitArguments : "")} --results-directory .{Path.DirectorySeparatorChar} --logger trx --blame-hang --blame-hang-timeout 30m {testFilter} -- {arguments}";
165156

166157
Log.LogMessage($"Creating work item with properties Identity: {assemblyName}, PayloadDirectory: {publishDirectory}, Command: {command}");
167158

0 commit comments

Comments
 (0)