Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -8,8 +8,11 @@ internal static class AzureDevOpsCommandLineOptions
public const string AzureDevOpsOptionName = "report-azdo";
public const string AzureDevOpsDemoteKnownFlaky = "report-azdo-demote-known-flaky";
public const string AzureDevOpsFlakyHistory = "report-azdo-flaky-history";
public const string AzureDevOpsProgress = "report-azdo-progress";
public const string AzureDevOpsQuarantineFile = "report-azdo-quarantine-file";
public const string AzureDevOpsReportSeverity = "report-azdo-severity";
public const string AzureDevOpsStackFrameFilter = "report-azdo-stackframe-filter";
public const string AzureDevOpsSummary = "report-azdo-summary";
public const string AzureDevOpsUploadArtifactExclude = "report-azdo-upload-artifact-exclude";
public const string AzureDevOpsUploadArtifactInclude = "report-azdo-upload-artifact-include";
public const string AzureDevOpsUploadArtifactName = "report-azdo-upload-artifact-name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ internal sealed class AzureDevOpsCommandLineProvider : CommandLineOptionsProvide

private static readonly string[] SeverityOptions = ["error", "warning"];

internal const int MaxStackFrameFilterPatterns = 16;
internal const int StackFrameFilterMatchTimeoutMs = 500;

private static readonly string DemoteKnownFlakyOptionDescriptionFormatted = string.Format(
CultureInfo.InvariantCulture,
AzureDevOpsResources.DemoteKnownFlakyOptionDescription,
AzureDevOpsReporter.KnownFlakyFailureRateThreshold * 100);

private static readonly string StackFrameFilterOptionDescriptionFormatted = string.Format(
CultureInfo.InvariantCulture,
AzureDevOpsResources.StackFrameFilterOptionDescription,
MaxStackFrameFilterPatterns,
StackFrameFilterMatchTimeoutMs);

public AzureDevOpsCommandLineProvider()
: base(
nameof(AzureDevOpsCommandLineProvider),
Expand All @@ -38,8 +47,11 @@ public AzureDevOpsCommandLineProvider()
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsOptionName, AzureDevOpsResources.OptionDescription, ArgumentArity.Zero, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsDemoteKnownFlaky, DemoteKnownFlakyOptionDescriptionFormatted, ArgumentArity.Zero, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsFlakyHistory, AzureDevOpsResources.FlakyHistoryOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsProgress, AzureDevOpsResources.ProgressOptionDescription, ArgumentArity.Zero, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsQuarantineFile, AzureDevOpsResources.QuarantineFileOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsReportSeverity, AzureDevOpsResources.SeverityOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsStackFrameFilter, StackFrameFilterOptionDescriptionFormatted, ArgumentArity.OneOrMore, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsSummary, AzureDevOpsResources.SummaryOptionDescription, ArgumentArity.ZeroOrOne, false),
Comment thread
Evangelink marked this conversation as resolved.
Resolved
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsUploadArtifactExclude, AzureDevOpsResources.UploadArtifactExcludeOptionDescription, ArgumentArity.ZeroOrMore, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsUploadArtifactInclude, AzureDevOpsResources.UploadArtifactIncludeOptionDescription, ArgumentArity.ZeroOrMore, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsUploadArtifactName, AzureDevOpsResources.UploadArtifactNameOptionDescription, ArgumentArity.ExactlyOne, false),
Expand All @@ -56,6 +68,7 @@ public override Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineO
AzureDevOpsCommandLineOptions.AzureDevOpsFlakyHistory => ValidateFlakyHistoryArgumentsAsync(arguments),
AzureDevOpsCommandLineOptions.AzureDevOpsReportSeverity when !SeverityOptions.Contains(arguments[0], StringComparer.OrdinalIgnoreCase)
=> ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, AzureDevOpsResources.InvalidSeverity, arguments[0])),
AzureDevOpsCommandLineOptions.AzureDevOpsStackFrameFilter => ValidateStackFrameFilterArgumentsAsync(arguments),
AzureDevOpsCommandLineOptions.AzureDevOpsUploadArtifacts when !ArtifactUploadModes.Contains(arguments[0], StringComparer.OrdinalIgnoreCase)
=> ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, AzureDevOpsResources.InvalidArtifactUploadMode, arguments[0])),
AzureDevOpsCommandLineOptions.AzureDevOpsUploadArtifactInclude or AzureDevOpsCommandLineOptions.AzureDevOpsUploadArtifactExclude
Expand All @@ -76,6 +89,10 @@ public override Task<ValidationResult> ValidateCommandLineOptionsAsync(ICommandL
{
errorMessage = AzureDevOpsResources.AzureDevOpsFlakyHistoryRequiresAzureDevOps;
}
else if (commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsProgress))
{
errorMessage = AzureDevOpsResources.AzureDevOpsProgressRequiresAzureDevOps;
}
else if (commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsQuarantineFile))
{
errorMessage = AzureDevOpsResources.AzureDevOpsQuarantineFileRequiresAzureDevOps;
Expand All @@ -84,6 +101,14 @@ public override Task<ValidationResult> ValidateCommandLineOptionsAsync(ICommandL
{
errorMessage = AzureDevOpsResources.AzureDevOpsReportSeverityRequiresAzureDevOps;
}
else if (commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsStackFrameFilter))
{
errorMessage = AzureDevOpsResources.AzureDevOpsStackFrameFilterRequiresAzureDevOps;
}
else if (commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsSummary))
{
errorMessage = AzureDevOpsResources.AzureDevOpsSummaryRequiresAzureDevOps;
}
}
else if (commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsDemoteKnownFlaky)
&& !commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsFlakyHistory))
Expand Down Expand Up @@ -154,4 +179,31 @@ private static Task<ValidationResult> ValidateFlakyHistoryArgumentsAsync(string[
&& days is >= 1 and <= 90
? ValidationResult.ValidTask
: ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, AzureDevOpsResources.InvalidFlakyHistoryDays, arguments[0]));

private static Task<ValidationResult> ValidateStackFrameFilterArgumentsAsync(string[] arguments)
{
if (arguments.Length > MaxStackFrameFilterPatterns)
{
return ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, AzureDevOpsResources.StackFrameFilterTooManyRegexes, MaxStackFrameFilterPatterns));
}

foreach (string pattern in arguments)
{
if (RoslynString.IsNullOrEmpty(pattern))
{
return ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, AzureDevOpsResources.InvalidStackFrameFilterRegex, pattern, "pattern is empty"));
}

try
{
_ = new Regex(pattern, RegexOptions.CultureInvariant | RegexOptions.Compiled, TimeSpan.FromMilliseconds(StackFrameFilterMatchTimeoutMs));
}
catch (ArgumentException ex)
{
return ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, AzureDevOpsResources.InvalidStackFrameFilterRegex, pattern, ex.Message));
}
}

return ValidationResult.ValidTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ public static void AddAzureDevOpsProvider(this ITestApplicationBuilder builder)
serviceProvider.GetTestApplicationModuleInfo(),
serviceProvider.GetLoggerFactory()));

var compositeSummaryReporter =
new CompositeExtensionFactory<AzureDevOpsSummaryReporter>(serviceProvider =>
new AzureDevOpsSummaryReporter(
serviceProvider.GetCommandLineOptions(),
serviceProvider.GetConfiguration(),
serviceProvider.GetEnvironment(),
serviceProvider.GetFileSystem(),
serviceProvider.GetOutputDevice(),
serviceProvider.GetTestApplicationModuleInfo(),
serviceProvider.GetLoggerFactory()));

var compositeProgressReporter =
new CompositeExtensionFactory<AzureDevOpsProgressReporter>(serviceProvider =>
new AzureDevOpsProgressReporter(
serviceProvider.GetCommandLineOptions(),
serviceProvider.GetEnvironment(),
serviceProvider.GetOutputDevice(),
serviceProvider.GetTestApplicationModuleInfo(),
serviceProvider.GetLoggerFactory()));

var compositeTestResultsPublisher =
new CompositeExtensionFactory<AzureDevOpsTestResultsPublisher>(serviceProvider =>
new AzureDevOpsTestResultsPublisher(
Expand Down Expand Up @@ -60,10 +80,14 @@ public static void AddAzureDevOpsProvider(this ITestApplicationBuilder builder)
historyService);
});
builder.TestHost.AddDataConsumer(compositeArtifactUploader);
builder.TestHost.AddDataConsumer(compositeSummaryReporter);
builder.TestHost.AddDataConsumer(compositeProgressReporter);
builder.TestHost.AddDataConsumer(compositeTestResultsPublisher);
builder.TestHost.AddTestSessionLifetimeHandler(serviceProvider =>
historyService ??= CreateHistoryService(serviceProvider));
builder.TestHost.AddTestSessionLifetimeHandler(compositeArtifactUploader);
builder.TestHost.AddTestSessionLifetimeHandler(compositeSummaryReporter);
builder.TestHost.AddTestSessionLifetimeHandler(compositeProgressReporter);
builder.TestHost.AddTestSessionLifetimeHandler(compositeTestResultsPublisher);
builder.CommandLine.AddProvider(() => new AzureDevOpsCommandLineProvider());
}
Expand Down
Loading