Skip to content

Commit e7abb69

Browse files
committed
Check for LimitProcessingConcurrencyTo
1 parent 87acdc3 commit e7abb69

3 files changed

Lines changed: 52 additions & 8 deletions

File tree

src/NServiceBus.AzureFunctions.Analyzer.Tests/AzureFunctionsConfigurationAnalyzerTests.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,47 @@ namespace NServiceBus.AzureFunctions.Analyzer.Tests
66
[TestFixture]
77
public class AzureFunctionsConfigurationAnalyzerTests : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
88
{
9-
// IEndpointInstance
10-
[TestCase("ServiceBusTriggeredEndpointConfiguration", "obj.AdvancedConfiguration.PurgeOnStartup(true)")]
11-
public Task DiagnosticIsReportedForCorePublicMethods(string type, string call)
9+
[Test]
10+
public Task DiagnosticIsReportedForPurgeOnStartup()
1211
{
1312
var source =
1413
$@"using NServiceBus;
1514
using System;
1615
using System.Threading.Tasks;
1716
class Foo
1817
{{
19-
void Bar({type} obj)
18+
void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
2019
{{
21-
[|{call}|];
20+
[|endpointConfig.AdvancedConfiguration.PurgeOnStartup(true)|];
21+
22+
var advancedConfig = endpointConfig.AdvancedConfiguration;
23+
[|advancedConfig.PurgeOnStartup(true)|];
2224
}}
2325
}}";
2426

2527
return Assert(AzureFunctionsDiagnostics.PurgeOnStartupNotAllowedId, source);
2628
}
29+
30+
[Test]
31+
public Task DiagnosticIsReportedForLimitMessageProcessingConcurrencyTo()
32+
{
33+
var source =
34+
$@"using NServiceBus;
35+
using System;
36+
using System.Threading.Tasks;
37+
class Foo
38+
{{
39+
void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
40+
{{
41+
[|endpointConfig.AdvancedConfiguration.LimitMessageProcessingConcurrencyTo(5)|];
42+
43+
var advancedConfig = endpointConfig.AdvancedConfiguration;
44+
[|advancedConfig.LimitMessageProcessingConcurrencyTo(5)|];
45+
}}
46+
}}";
47+
48+
return Assert(AzureFunctionsDiagnostics.LimitMessageProcessingToNotAllowedId, source);
49+
}
50+
2751
}
2852
}

src/NServiceBus.AzureFunctions.Analyzer/AzureFunctionsConfigurationAnalyzer.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NServiceBus.AzureFunctions.Analyzer
22
{
3+
using System.Collections.Generic;
34
using System.Collections.Immutable;
45
using Microsoft.CodeAnalysis;
56
using Microsoft.CodeAnalysis.CSharp;
@@ -11,7 +12,8 @@ namespace NServiceBus.AzureFunctions.Analyzer
1112
public class AzureFunctionsConfigurationAnalyzer : DiagnosticAnalyzer
1213
{
1314
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
14-
AzureFunctionsDiagnostics.PurgeOnStartupNotAllowed
15+
AzureFunctionsDiagnostics.PurgeOnStartupNotAllowed,
16+
AzureFunctionsDiagnostics.LimitMessageProcessingToNotAllowed
1517
);
1618

1719
public override void Initialize(AnalysisContext context)
@@ -33,7 +35,7 @@ static void Analyze(SyntaxNodeAnalysisContext context)
3335
return;
3436
}
3537

36-
if (memberAccessExpression.Name.Identifier.Text != "PurgeOnStartup")
38+
if (!NotAllowedEndpointConfigurationMethods.TryGetValue(memberAccessExpression.Name.Identifier.Text, out var diagnosticDescriptor))
3739
{
3840
return;
3941
}
@@ -47,8 +49,15 @@ static void Analyze(SyntaxNodeAnalysisContext context)
4749

4850
if (methodSymbol.ReceiverType.ToString() == "NServiceBus.EndpointConfiguration")
4951
{
50-
context.ReportDiagnostic(AzureFunctionsDiagnostics.PurgeOnStartupNotAllowed, invocationExpression);
52+
context.ReportDiagnostic(diagnosticDescriptor, invocationExpression);
5153
}
5254
}
55+
56+
static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedEndpointConfigurationMethods
57+
= new Dictionary<string, DiagnosticDescriptor>
58+
{
59+
["PurgeOnStartup"] = AzureFunctionsDiagnostics.PurgeOnStartupNotAllowed,
60+
["LimitMessageProcessingConcurrencyTo"] = AzureFunctionsDiagnostics.LimitMessageProcessingToNotAllowed
61+
};
5362
}
5463
}

src/NServiceBus.AzureFunctions.Analyzer/AzureFunctionsDiagnostics.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
public static class AzureFunctionsDiagnostics
66
{
77
public const string PurgeOnStartupNotAllowedId = "NSBAF0001";
8+
public const string LimitMessageProcessingToNotAllowedId = "NSBAF0002";
89

910
const string DiagnosticCategory = "NServiceBus.AzureFunctions";
1011

@@ -16,5 +17,15 @@ public static class AzureFunctionsDiagnostics
1617
defaultSeverity: DiagnosticSeverity.Error,
1718
isEnabledByDefault: true
1819
);
20+
21+
internal static readonly DiagnosticDescriptor LimitMessageProcessingToNotAllowed = new DiagnosticDescriptor(
22+
id: LimitMessageProcessingToNotAllowedId,
23+
title: "LimitMessageProcessing is not supported in Azure Functions",
24+
messageFormat: "Azure Functions endpoints do not control the message receiver and cannot limit message processing concurrency.",
25+
category: DiagnosticCategory,
26+
defaultSeverity: DiagnosticSeverity.Error,
27+
isEnabledByDefault: true
28+
);
29+
1930
}
2031
}

0 commit comments

Comments
 (0)