Skip to content

Commit 392eff4

Browse files
authored
Shorten pipe names (#3183)
1 parent 5a993c5 commit 392eff4

File tree

6 files changed

+38
-27
lines changed

6 files changed

+38
-27
lines changed

src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpActivityIndicator.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ public HangDumpActivityIndicator(
6262
if (_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName) &&
6363
!_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey))
6464
{
65-
string namedPipeSuffix = _environment.GetEnvironmentVariable(HangDumpConfiguration.MutexNameSuffix) ?? throw new InvalidOperationException($"Expected {HangDumpConfiguration.MutexNameSuffix} environment variable set.");
65+
string namedPipeSuffix = _environment.GetEnvironmentVariable(HangDumpConfiguration.MutexNameSuffix)
66+
?? throw new InvalidOperationException($"Expected {HangDumpConfiguration.MutexNameSuffix} environment variable set.");
67+
// @Marco: Why do we need to duplicate logic here instead of using HangDumpConfiguration.PipeNameKey?
6668
string pipeNameEnvironmentVariable = $"{HangDumpConfiguration.PipeName}_{FNV_1aHashHelper.ComputeStringHash(testApplicationModuleInfo.GetCurrentTestApplicationFullPath())}_{namedPipeSuffix}";
67-
string namedPipeName = _environment.GetEnvironmentVariable(pipeNameEnvironmentVariable) ?? throw new InvalidOperationException($"Expected {pipeNameEnvironmentVariable} environment variable set.");
69+
string namedPipeName = _environment.GetEnvironmentVariable(pipeNameEnvironmentVariable)
70+
?? throw new InvalidOperationException($"Expected {pipeNameEnvironmentVariable} environment variable set.");
6871
_namedPipeClient = new NamedPipeClient(namedPipeName);
6972
_namedPipeClient.RegisterSerializer(new ActivityIndicatorMutexNameRequestSerializer(), typeof(ActivityIndicatorMutexNameRequest));
7073
_namedPipeClient.RegisterSerializer(new VoidResponseSerializer(), typeof(VoidResponse));
@@ -114,7 +117,8 @@ await _namedPipeClient.RequestReplyAsync<ActivityIndicatorMutexNameRequest, Void
114117
await _logger.LogTraceAsync($"Mutex '{_mutexName}' sent to the process lifetime handler");
115118

116119
// Setup the server channel with the testhost controller
117-
_pipeNameDescription = NamedPipeServer.GetPipeName($"HangDumpActivityIndicator_{Guid.NewGuid():N}");
120+
_pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N"));
121+
_logger.LogTrace($"Hang dump pipe name: '{_pipeNameDescription.Name}'");
118122
_singleConnectionNamedPipeServer = new(_pipeNameDescription, CallbackAsync, _environment, _logger, _task, cancellationToken);
119123
_singleConnectionNamedPipeServer.RegisterSerializer(new GetInProgressTestsResponseSerializer(), typeof(GetInProgressTestsResponse));
120124
_singleConnectionNamedPipeServer.RegisterSerializer(new GetInProgressTestsRequestSerializer(), typeof(GetInProgressTestsRequest));

src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpConfiguration.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public HangDumpConfiguration(ITestApplicationModuleInfo testApplicationModuleInf
2020
MutexSuffix = mutexSuffix;
2121
}
2222

23-
public string PipeNameKey { get; private set; }
23+
public string PipeNameKey { get; }
2424

25-
public string PipeNameValue { get; private set; }
25+
public string PipeNameValue { get; }
2626

27-
public string MutexSuffix { get; private set; }
27+
public string MutexSuffix { get; }
2828
}

src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void AddHangDumpProvider(this ITestApplicationBuilder builder)
1616
{
1717
CurrentTestApplicationModuleInfo testApplicationModuleInfo = new(new SystemEnvironment(), new SystemProcessHandler());
1818
string mutexSuffix = Guid.NewGuid().ToString("N");
19-
PipeNameDescription pipeNameDescription = NamedPipeServer.GetPipeName($"hangdumpgeneratorpipename.{FNV_1aHashHelper.ComputeStringHash(testApplicationModuleInfo.GetCurrentTestApplicationFullPath())}_{mutexSuffix}");
19+
PipeNameDescription pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N"));
2020
HangDumpConfiguration hangDumpConfiguration = new(testApplicationModuleInfo, pipeNameDescription, mutexSuffix);
2121

2222
builder.TestHostControllers.AddProcessLifetimeHandler(serviceProvider

src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxEnvironmentVariableProvider.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public Task<bool> IsEnabledAsync()
3737
=> Task.FromResult(
3838
// TrxReportGenerator is enabled only when trx report is enabled
3939
_commandLineOptions.IsOptionSet(TrxReportGeneratorCommandLine.TrxReportOptionName)
40-
// TestController is not used when we run in server mode
41-
&& !_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey)
42-
// If crash dump is not enabled we run trx in-process only
43-
&& _commandLineOptions.IsOptionSet(CrashDumpCommandLineOptions.CrashDumpOptionName));
40+
// TestController is not used when we run in server mode
41+
&& !_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey)
42+
// If crash dump is not enabled we run trx in-process only
43+
&& _commandLineOptions.IsOptionSet(CrashDumpCommandLineOptions.CrashDumpOptionName));
4444
#pragma warning restore SA1114 // Parameter list should follow declaration
4545

4646
public Task UpdateAsync(IEnvironmentVariables environmentVariables)

src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportExtensions.cs

+22-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public static void AddTrxReportProvider(this ITestApplicationBuilder builder)
2222
throw new InvalidOperationException(ExtensionResources.InvalidTestApplicationBuilderType);
2323
}
2424

25-
PipeNameDescription pipeNameDescription = NamedPipeServer.GetPipeName($"trxpipename.{Guid.NewGuid():N}");
2625
var commandLine = new TrxReportGeneratorCommandLine();
2726

2827
var compositeTestSessionTrxService =
@@ -42,29 +41,37 @@ public static void AddTrxReportProvider(this ITestApplicationBuilder builder)
4241
serviceProvider.GetLoggerFactory().CreateLogger<TrxReportGenerator>()));
4342

4443
builder.TestHost.AddTestApplicationLifecycleCallbacks(serviceProvider =>
45-
new TrxTestApplicationLifecycleCallbacks(
46-
serviceProvider.GetCommandLineOptions(),
47-
serviceProvider.GetEnvironment()));
44+
new TrxTestApplicationLifecycleCallbacks(
45+
serviceProvider.GetCommandLineOptions(),
46+
serviceProvider.GetEnvironment()));
4847
builder.TestHost.AddDataConsumer(compositeTestSessionTrxService);
4948
builder.TestHost.AddTestSessionLifetimeHandle(compositeTestSessionTrxService);
5049

5150
builder.CommandLine.AddProvider(() => commandLine);
5251

52+
PipeNameDescription pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N"));
5353
var compositeLifeTimeHandler =
5454
new CompositeExtensionFactory<TrxProcessLifetimeHandler>(serviceProvider =>
55-
new TrxProcessLifetimeHandler(
56-
serviceProvider.GetCommandLineOptions(),
57-
serviceProvider.GetEnvironment(),
58-
serviceProvider.GetLoggerFactory(),
59-
serviceProvider.GetMessageBus(),
60-
serviceProvider.GetTestApplicationModuleInfo(),
61-
serviceProvider.GetConfiguration(),
62-
serviceProvider.GetSystemClock(),
63-
serviceProvider.GetTask(),
64-
pipeNameDescription));
55+
{
56+
serviceProvider.GetLoggerFactory().CreateLogger<TrxProcessLifetimeHandler>().LogTrace($"TRX pipe name: '{pipeNameDescription.Name}");
57+
return new TrxProcessLifetimeHandler(
58+
serviceProvider.GetCommandLineOptions(),
59+
serviceProvider.GetEnvironment(),
60+
serviceProvider.GetLoggerFactory(),
61+
serviceProvider.GetMessageBus(),
62+
serviceProvider.GetTestApplicationModuleInfo(),
63+
serviceProvider.GetConfiguration(),
64+
serviceProvider.GetSystemClock(),
65+
serviceProvider.GetTask(),
66+
pipeNameDescription);
67+
});
6568
((TestHostControllersManager)builder.TestHostControllers).AddDataConsumer(compositeLifeTimeHandler);
6669
builder.TestHostControllers.AddProcessLifetimeHandler(compositeLifeTimeHandler);
67-
builder.TestHostControllers.AddEnvironmentVariableProvider(serviceProvider => new TrxEnvironmentVariableProvider(serviceProvider.GetCommandLineOptions(), pipeNameDescription.Name));
70+
builder.TestHostControllers.AddEnvironmentVariableProvider(serviceProvider =>
71+
{
72+
serviceProvider.GetLoggerFactory().CreateLogger<TrxEnvironmentVariableProvider>().LogTrace($"TRX pipe name: '{pipeNameDescription.Name}");
73+
return new TrxEnvironmentVariableProvider(serviceProvider.GetCommandLineOptions(), pipeNameDescription.Name);
74+
});
6875

6976
ToolTrxCompareFactory toolTrxCompareFactory = new();
7077
TrxCompareToolCommandLine createTrxCompareToolCommandLine = toolTrxCompareFactory.CreateTrxCompareToolCommandLine();

src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public InvokeTestingPlatformTask()
5050
Debugger.Launch();
5151
}
5252

53-
_pipeNameDescription = NamedPipeServer.GetPipeName($"{Guid.NewGuid():N}");
53+
_pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N"));
5454
}
5555

5656
internal InvokeTestingPlatformTask(IFileSystem fileSystem)

0 commit comments

Comments
 (0)