Skip to content

Commit

Permalink
Comments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalac committed Sep 13, 2023
1 parent dcb96d5 commit eeb0511
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
namespace NServiceBus.AzureFunctions.Analyzer.Tests
{
using System.Threading;
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using static AzureFunctionsDiagnostics;

[TestFixture]
public class AzureFunctionsConfigurationAnalyzerTests : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
public class ConfigurationAnalyzerTests : AnalyzerTestFixture<ConfigurationAnalyzer>
{
[TestCase("DefineCriticalErrorAction((errorContext, cancellationToken) => Task.CompletedTask)", DefineCriticalErrorActionNotAllowedId)]
[TestCase("LimitMessageProcessingConcurrencyTo(5)", LimitMessageProcessingToNotAllowedId)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using static AzureFunctionsDiagnostics;

[TestFixture]
public class AzureFunctionsConfigurationAnalyzerTestsCSharp8 : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
public class ConfigurationAnalyzerTestsCSharp8 : AnalyzerTestFixture<ConfigurationAnalyzer>
{
// HINT: In C# 7 this call is ambiguous with the LearningTransport version as the compiler cannot differentiate method calls via generic type constraints
[TestCase("UseTransport<AzureServiceBusTransport>()", UseTransportNotAllowedId)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ namespace NServiceBus.AzureFunctions.Analyzer.Tests
using static AzureFunctionsDiagnostics;

[TestFixture]
public class AzureFunctionsSendReplyOptionsAnalyzerTests : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
public class OptionsAnalyzerTests : AnalyzerTestFixture<ConfigurationAnalyzer>
{
[TestCase("SendOptions", "RouteReplyToAnyInstance", RouteReplyToAnyInstanceNotAllowedId)]
[TestCase("SendOptions", "RouteReplyToThisInstance", RouteReplyToThisInstanceNotAllowedId)]
[TestCase("SendOptions", "RouteToThisInstance", RouteToThisInstanceNotAllowedId)]
[TestCase("ReplyOptions", "RouteReplyToAnyInstance", RouteReplyToAnyInstanceNotAllowedId)]
[TestCase("ReplyOptions", "RouteReplyToThisInstance", RouteReplyToThisInstanceNotAllowedId)]
public Task DiagnosticIsReportedForOptions(string optionsType, string method, string diagnosticId)
{
Expand All @@ -27,8 +25,6 @@ void Bar({optionsType} options)
return Assert(diagnosticId, source);
}


[TestCase("SomeOtherClass", "RouteReplyToAnyInstance", RouteReplyToAnyInstanceNotAllowedId)]
[TestCase("SomeOtherClass", "RouteReplyToThisInstance", RouteReplyToThisInstanceNotAllowedId)]
[TestCase("SomeOtherClass", "RouteToThisInstance", RouteToThisInstanceNotAllowedId)]
public Task DiagnosticIsNotReportedForOtherOptions(string optionsType, string method, string diagnosticId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ namespace NServiceBus.AzureFunctions.Analyzer.Tests
using static AzureFunctionsDiagnostics;

[TestFixture]
public class AzureFunctionsTransportAnalyzerTests : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
public class TransportConfigurationAnalyzerTests : AnalyzerTestFixture<ConfigurationAnalyzer>
{
[TestCase("TransportTransactionMode", "TransportTransactionMode.None", TransportTransactionModeNotAllowedId)]
[TestCase("EnablePartitioning", "true", EnablePartitioningNotAllowedId)]
[TestCase("EntityMaximumSize", "5", EntityMaximumSizeNotAllowedId)]
[TestCase("MaxAutoLockRenewalDuration", "new System.TimeSpan(0, 0, 5, 0)", MaxAutoLockRenewalDurationNotAllowedId)]
[TestCase("PrefetchCount", "5", PrefetchCountNotAllowedId)]
[TestCase("PrefetchMultiplier", "5", PrefetchMultiplierNotAllowedId)]
[TestCase("TimeToWaitBeforeTriggeringCircuitBreaker", "new System.TimeSpan(0, 0, 5, 0)", TimeToWaitBeforeTriggeringCircuitBreakerNotAllowedId)]
public Task DiagnosticIsReportedTransportConfiguration(string configName, string configValue, string diagnosticId)
public Task DiagnosticIsReportedTransportConfigurationDirect(string configName, string configValue, string diagnosticId)
{
var source =
$@"using NServiceBus;
Expand All @@ -27,7 +29,26 @@ void Direct(ServiceBusTriggeredEndpointConfiguration endpointConfig)
var transportConfig = endpointConfig.Transport;
[|transportConfig.{configName}|] = {configValue};
}}
}}";

return Assert(diagnosticId, source);
}

[TestCase("Transactions", "TransportTransactionMode.None", TransportTransactionModeNotAllowedId)]
[TestCase("EnablePartitioning", "", EnablePartitioningNotAllowedId)]
[TestCase("EntityMaximumSize", "5", EntityMaximumSizeNotAllowedId)]
[TestCase("MaxAutoLockRenewalDuration", "new System.TimeSpan(0, 0, 5, 0)", MaxAutoLockRenewalDurationNotAllowedId)]
[TestCase("PrefetchCount", "5", PrefetchCountNotAllowedId)]
[TestCase("PrefetchMultiplier", "5", PrefetchMultiplierNotAllowedId)]
[TestCase("TimeToWaitBeforeTriggeringCircuitBreaker", "new System.TimeSpan(0, 0, 5, 0)", TimeToWaitBeforeTriggeringCircuitBreakerNotAllowedId)]
public Task DiagnosticIsReportedTransportConfigurationExtension(string configName, string configValue, string diagnosticId)
{
var source =
$@"using NServiceBus;
using System;
using System.Threading.Tasks;
class Foo
{{
void Extension(TransportExtensions<AzureServiceBusTransport> transportExtension)
{{
[|transportExtension.{configName}({configValue})|];
Expand All @@ -37,6 +58,7 @@ void Extension(TransportExtensions<AzureServiceBusTransport> transportExtension)
return Assert(diagnosticId, source);
}

[TestCase("EnablePartitioning", "true", EnablePartitioningNotAllowedId)]
[TestCase("EntityMaximumSize", "5", EntityMaximumSizeNotAllowedId)]
[TestCase("MaxAutoLockRenewalDuration", "new System.TimeSpan(0, 0, 5, 0)", MaxAutoLockRenewalDurationNotAllowedId)]
[TestCase("PrefetchCount", "5", PrefetchCountNotAllowedId)]
Expand All @@ -52,6 +74,7 @@ public Task DiagnosticIsNotReportedForNonTransportConfiguration(string configNam
class SomeOtherClass
{{
internal int EntityMaximumSize {{ get; set; }}
internal bool EnablePartitioning {{ get; set; }}
internal TimeSpan MaxAutoLockRenewalDuration {{ get; set; }}
internal int PrefetchCount {{ get; set; }}
internal int PrefetchMultiplier {{ get; set; }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ public static class AzureFunctionsDiagnostics
public const string OverrideLocalAddressNotAllowedId = "NSBFUNC009";
public const string RouteReplyToThisInstanceNotAllowedId = "NSBFUNC010";
public const string RouteToThisInstanceNotAllowedId = "NSBFUNC011";
public const string RouteReplyToAnyInstanceNotAllowedId = "NSBFUNC012";

public const string TransportTransactionModeNotAllowedId = "NSBFUNC012";
public const string MaxAutoLockRenewalDurationNotAllowedId = "NSBFUNC013";
public const string PrefetchCountNotAllowedId = "NSBFUNC014";
public const string PrefetchMultiplierNotAllowedId = "NSBFUNC015";
public const string TimeToWaitBeforeTriggeringCircuitBreakerNotAllowedId = "NSBFUNC016";

public const string EntityMaximumSizeNotAllowedId = "NSBFUNC017";
public const string EnablePartitioningNotAllowedId = "NSBFUNC018";

const string DiagnosticCategory = "NServiceBus.AzureFunctions";

internal static readonly DiagnosticDescriptor PurgeOnStartupNotAllowed = new DiagnosticDescriptor(
id: PurgeOnStartupNotAllowedId,
title: "PurgeOnStartup is not supported in Azure Functions",
messageFormat: "Azure Functions endpoints are started when the first message arrives. PurgeOnStartup may purge whenever a new instance is started.",
messageFormat: "Azure Functions endpoints do not support PurgeOnStartup.",
category: DiagnosticCategory,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true
Expand All @@ -36,7 +36,7 @@ public static class AzureFunctionsDiagnostics
internal static readonly DiagnosticDescriptor LimitMessageProcessingToNotAllowed = new DiagnosticDescriptor(
id: LimitMessageProcessingToNotAllowedId,
title: "LimitMessageProcessing is not supported in Azure Functions",
messageFormat: "Azure Functions endpoints do not control the message receiver and cannot limit message processing concurrency.",
messageFormat: "Concurrency-related settings are controlled via the Azure Function host.json configuration file.",
category: DiagnosticCategory,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true
Expand Down Expand Up @@ -81,7 +81,7 @@ public static class AzureFunctionsDiagnostics
internal static readonly DiagnosticDescriptor OverrideLocalAddressNotAllowed = new DiagnosticDescriptor(
id: OverrideLocalAddressNotAllowedId,
title: "OverrideLocalAddress is not supported in Azure Functions",
messageFormat: "Azure Functions endpoints do not control the message receiver and cannot decide the local address.",
messageFormat: "The NServiceBus endpoint address in Azure Functions is determined by the ServiceBusTrigger attribute.",
category: DiagnosticCategory,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true
Expand All @@ -105,15 +105,6 @@ public static class AzureFunctionsDiagnostics
isEnabledByDefault: true
);

internal static readonly DiagnosticDescriptor RouteReplyToAnyInstanceNotAllowed = new DiagnosticDescriptor(
id: RouteReplyToAnyInstanceNotAllowedId,
title: "RouteReplyToAnyInstance is not supported in Azure Functions",
messageFormat: "Azure Functions endpoints do not control the message receiver and by default route the replies to any instance.",
category: DiagnosticCategory,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true
);

internal static readonly DiagnosticDescriptor MaxAutoLockRenewalDurationNotAllowed = new DiagnosticDescriptor(
id: MaxAutoLockRenewalDurationNotAllowedId,
title: "MaxAutoLockRenewalDuration is not supported in Azure Functions",
Expand Down Expand Up @@ -158,5 +149,23 @@ public static class AzureFunctionsDiagnostics
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true
);

internal static readonly DiagnosticDescriptor EnablePartitioningNotAllowed = new DiagnosticDescriptor(
id: EnablePartitioningNotAllowedId,
title: "EnablePartitioning is not supported in Azure Functions",
messageFormat: "Azure Functions endpoints do not support automatic queue creation.",
category: DiagnosticCategory,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true
);

internal static readonly DiagnosticDescriptor TransportTransactionModeNotAllowed = new DiagnosticDescriptor(
id: TransportTransactionModeNotAllowedId,
title: "TransportTransactionMode is not supported in Azure Functions",
messageFormat: "Transport TransactionMode is controlled by the Azure Service Bus trigger and cannot be configured via the NServiceBus transport configuration API when using Azure Functions.",
category: DiagnosticCategory,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NServiceBus.AzureFunctions.Analyzer
using NServiceBus.AzureFunctions.Analyzer.Extensions;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class AzureFunctionsConfigurationAnalyzer : DiagnosticAnalyzer
public class ConfigurationAnalyzer : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
AzureFunctionsDiagnostics.PurgeOnStartupNotAllowed,
Expand All @@ -21,12 +21,13 @@ public class AzureFunctionsConfigurationAnalyzer : DiagnosticAnalyzer
AzureFunctionsDiagnostics.OverrideLocalAddressNotAllowed,
AzureFunctionsDiagnostics.RouteReplyToThisInstanceNotAllowed,
AzureFunctionsDiagnostics.RouteToThisInstanceNotAllowed,
AzureFunctionsDiagnostics.RouteReplyToAnyInstanceNotAllowed,
AzureFunctionsDiagnostics.MaxAutoLockRenewalDurationNotAllowed,
AzureFunctionsDiagnostics.PrefetchCountNotAllowed,
AzureFunctionsDiagnostics.PrefetchMultiplierNotAllowed,
AzureFunctionsDiagnostics.TimeToWaitBeforeTriggeringCircuitBreakerNotAllowed,
AzureFunctionsDiagnostics.EntityMaximumSizeNotAllowed
AzureFunctionsDiagnostics.EntityMaximumSizeNotAllowed,
AzureFunctionsDiagnostics.EnablePartitioningNotAllowed,
AzureFunctionsDiagnostics.TransportTransactionModeNotAllowed
);

static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedEndpointConfigurationMethods
Expand All @@ -46,7 +47,6 @@ static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedSendAndReplyO
{
["RouteReplyToThisInstance"] = AzureFunctionsDiagnostics.RouteReplyToThisInstanceNotAllowed,
["RouteToThisInstance"] = AzureFunctionsDiagnostics.RouteToThisInstanceNotAllowed,
["RouteReplyToAnyInstance"] = AzureFunctionsDiagnostics.RouteReplyToAnyInstanceNotAllowed
};

static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedTransportSettings
Expand All @@ -56,7 +56,10 @@ static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedTransportSett
["PrefetchCount"] = AzureFunctionsDiagnostics.PrefetchCountNotAllowed,
["PrefetchMultiplier"] = AzureFunctionsDiagnostics.PrefetchMultiplierNotAllowed,
["TimeToWaitBeforeTriggeringCircuitBreaker"] = AzureFunctionsDiagnostics.TimeToWaitBeforeTriggeringCircuitBreakerNotAllowed,
["EntityMaximumSize"] = AzureFunctionsDiagnostics.EntityMaximumSizeNotAllowed
["EntityMaximumSize"] = AzureFunctionsDiagnostics.EntityMaximumSizeNotAllowed,
["EnablePartitioning"] = AzureFunctionsDiagnostics.EnablePartitioningNotAllowed,
["TransportTransactionMode"] = AzureFunctionsDiagnostics.TransportTransactionModeNotAllowed,
["Transactions"] = AzureFunctionsDiagnostics.TransportTransactionModeNotAllowed
};

public override void Initialize(AnalysisContext context)
Expand Down Expand Up @@ -106,7 +109,7 @@ static void AnalyzeTransport(SyntaxNodeAnalysisContext context)
return;
}

if (propertySymbol.ContainingType.ToString() == "NServiceBus.AzureServiceBusTransport")
if (propertySymbol.ContainingType.ToString() == "NServiceBus.AzureServiceBusTransport" || propertySymbol.ContainingType.ToString() == "NServiceBus.Transport.TransportDefinition")
{
context.ReportDiagnostic(diagnosticDescriptor, memberAccess);

Expand Down

0 comments on commit eeb0511

Please sign in to comment.