Skip to content

Shorten pipe names #3183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ public HangDumpActivityIndicator(
if (_commandLineOptions.IsOptionSet(HangDumpCommandLineProvider.HangDumpOptionName) &&
!_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey))
{
string namedPipeSuffix = _environment.GetEnvironmentVariable(HangDumpConfiguration.MutexNameSuffix) ?? throw new InvalidOperationException($"Expected {HangDumpConfiguration.MutexNameSuffix} environment variable set.");
string namedPipeSuffix = _environment.GetEnvironmentVariable(HangDumpConfiguration.MutexNameSuffix)
?? throw new InvalidOperationException($"Expected {HangDumpConfiguration.MutexNameSuffix} environment variable set.");
// @Marco: Why do we need to duplicate logic here instead of using HangDumpConfiguration.PipeNameKey?
Copy link
Contributor

@MarcoRossignoli MarcoRossignoli Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Evangelink typo?

string pipeNameEnvironmentVariable = $"{HangDumpConfiguration.PipeName}_{FNV_1aHashHelper.ComputeStringHash(testApplicationModuleInfo.GetCurrentTestApplicationFullPath())}_{namedPipeSuffix}";
string namedPipeName = _environment.GetEnvironmentVariable(pipeNameEnvironmentVariable) ?? throw new InvalidOperationException($"Expected {pipeNameEnvironmentVariable} environment variable set.");
string namedPipeName = _environment.GetEnvironmentVariable(pipeNameEnvironmentVariable)
?? throw new InvalidOperationException($"Expected {pipeNameEnvironmentVariable} environment variable set.");
_namedPipeClient = new NamedPipeClient(namedPipeName);
_namedPipeClient.RegisterSerializer(new ActivityIndicatorMutexNameRequestSerializer(), typeof(ActivityIndicatorMutexNameRequest));
_namedPipeClient.RegisterSerializer(new VoidResponseSerializer(), typeof(VoidResponse));
Expand Down Expand Up @@ -114,7 +117,8 @@ await _namedPipeClient.RequestReplyAsync<ActivityIndicatorMutexNameRequest, Void
await _logger.LogTraceAsync($"Mutex '{_mutexName}' sent to the process lifetime handler");

// Setup the server channel with the testhost controller
_pipeNameDescription = NamedPipeServer.GetPipeName($"HangDumpActivityIndicator_{Guid.NewGuid():N}");
_pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N"));
_logger.LogTrace($"Hang dump pipe name: '{_pipeNameDescription.Name}'");
_singleConnectionNamedPipeServer = new(_pipeNameDescription, CallbackAsync, _environment, _logger, _task, cancellationToken);
_singleConnectionNamedPipeServer.RegisterSerializer(new GetInProgressTestsResponseSerializer(), typeof(GetInProgressTestsResponse));
_singleConnectionNamedPipeServer.RegisterSerializer(new GetInProgressTestsRequestSerializer(), typeof(GetInProgressTestsRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public HangDumpConfiguration(ITestApplicationModuleInfo testApplicationModuleInf
MutexSuffix = mutexSuffix;
}

public string PipeNameKey { get; private set; }
public string PipeNameKey { get; }

public string PipeNameValue { get; private set; }
public string PipeNameValue { get; }

public string MutexSuffix { get; private set; }
public string MutexSuffix { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void AddHangDumpProvider(this ITestApplicationBuilder builder)
{
CurrentTestApplicationModuleInfo testApplicationModuleInfo = new(new SystemEnvironment(), new SystemProcessHandler());
string mutexSuffix = Guid.NewGuid().ToString("N");
PipeNameDescription pipeNameDescription = NamedPipeServer.GetPipeName($"hangdumpgeneratorpipename.{FNV_1aHashHelper.ComputeStringHash(testApplicationModuleInfo.GetCurrentTestApplicationFullPath())}_{mutexSuffix}");
PipeNameDescription pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N"));
HangDumpConfiguration hangDumpConfiguration = new(testApplicationModuleInfo, pipeNameDescription, mutexSuffix);

builder.TestHostControllers.AddProcessLifetimeHandler(serviceProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public Task<bool> IsEnabledAsync()
=> Task.FromResult(
// TrxReportGenerator is enabled only when trx report is enabled
_commandLineOptions.IsOptionSet(TrxReportGeneratorCommandLine.TrxReportOptionName)
// TestController is not used when we run in server mode
&& !_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey)
// If crash dump is not enabled we run trx in-process only
&& _commandLineOptions.IsOptionSet(CrashDumpCommandLineOptions.CrashDumpOptionName));
// TestController is not used when we run in server mode
&& !_commandLineOptions.IsOptionSet(PlatformCommandLineProvider.ServerOptionKey)
// If crash dump is not enabled we run trx in-process only
&& _commandLineOptions.IsOptionSet(CrashDumpCommandLineOptions.CrashDumpOptionName));
#pragma warning restore SA1114 // Parameter list should follow declaration

public Task UpdateAsync(IEnvironmentVariables environmentVariables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static void AddTrxReportProvider(this ITestApplicationBuilder builder)
throw new InvalidOperationException(ExtensionResources.InvalidTestApplicationBuilderType);
}

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

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

builder.TestHost.AddTestApplicationLifecycleCallbacks(serviceProvider =>
new TrxTestApplicationLifecycleCallbacks(
serviceProvider.GetCommandLineOptions(),
serviceProvider.GetEnvironment()));
new TrxTestApplicationLifecycleCallbacks(
serviceProvider.GetCommandLineOptions(),
serviceProvider.GetEnvironment()));
builder.TestHost.AddDataConsumer(compositeTestSessionTrxService);
builder.TestHost.AddTestSessionLifetimeHandle(compositeTestSessionTrxService);

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

PipeNameDescription pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N"));
var compositeLifeTimeHandler =
new CompositeExtensionFactory<TrxProcessLifetimeHandler>(serviceProvider =>
new TrxProcessLifetimeHandler(
serviceProvider.GetCommandLineOptions(),
serviceProvider.GetEnvironment(),
serviceProvider.GetLoggerFactory(),
serviceProvider.GetMessageBus(),
serviceProvider.GetTestApplicationModuleInfo(),
serviceProvider.GetConfiguration(),
serviceProvider.GetSystemClock(),
serviceProvider.GetTask(),
pipeNameDescription));
{
serviceProvider.GetLoggerFactory().CreateLogger<TrxProcessLifetimeHandler>().LogTrace($"TRX pipe name: '{pipeNameDescription.Name}");
return new TrxProcessLifetimeHandler(
serviceProvider.GetCommandLineOptions(),
serviceProvider.GetEnvironment(),
serviceProvider.GetLoggerFactory(),
serviceProvider.GetMessageBus(),
serviceProvider.GetTestApplicationModuleInfo(),
serviceProvider.GetConfiguration(),
serviceProvider.GetSystemClock(),
serviceProvider.GetTask(),
pipeNameDescription);
});
((TestHostControllersManager)builder.TestHostControllers).AddDataConsumer(compositeLifeTimeHandler);
builder.TestHostControllers.AddProcessLifetimeHandler(compositeLifeTimeHandler);
builder.TestHostControllers.AddEnvironmentVariableProvider(serviceProvider => new TrxEnvironmentVariableProvider(serviceProvider.GetCommandLineOptions(), pipeNameDescription.Name));
builder.TestHostControllers.AddEnvironmentVariableProvider(serviceProvider =>
{
serviceProvider.GetLoggerFactory().CreateLogger<TrxEnvironmentVariableProvider>().LogTrace($"TRX pipe name: '{pipeNameDescription.Name}");
return new TrxEnvironmentVariableProvider(serviceProvider.GetCommandLineOptions(), pipeNameDescription.Name);
});

ToolTrxCompareFactory toolTrxCompareFactory = new();
TrxCompareToolCommandLine createTrxCompareToolCommandLine = toolTrxCompareFactory.CreateTrxCompareToolCommandLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public InvokeTestingPlatformTask()
Debugger.Launch();
}

_pipeNameDescription = NamedPipeServer.GetPipeName($"{Guid.NewGuid():N}");
_pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N"));
}

internal InvokeTestingPlatformTask(IFileSystem fileSystem)
Expand Down