Add Directory.Build.props. (#2120)

* Add Directory.Build.props.

* Adjust Analysis related properties and add conditional enablement for ContinuousIntegrationBuild.

* Adopt new changes in master

---------

Co-authored-by: christian <6939810+chkr1011@users.noreply.github.com>
This commit is contained in:
老九
2025-10-20 13:32:31 +02:00
committed by GitHub
co-authored by christian
parent e791d9aba4
commit 37c1eecce5
76 changed files with 442 additions and 520 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ namespace MQTTnet.TestApp;
public sealed class AsyncLockTest
{
public async Task Run()
public static async Task Run()
{
try
{
@@ -3,17 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<DebugType>Full</DebugType>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
<DisableImplicitAspNetCoreAnalyzers>true</DisableImplicitAspNetCoreAnalyzers>
<NoWarn>1591;NETSDK1138;NU1803;NU1901;NU1902</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NuGetAuditMode>all</NuGetAuditMode>
<NuGetAudit>true</NuGetAudit>
<NuGetAuditLevel>low</NuGetAuditLevel>
<AnalysisLevel>latest-Recommended</AnalysisLevel>
</PropertyGroup>
<ItemGroup>
@@ -14,7 +14,7 @@ namespace MQTTnet.TestApp;
/// the number of messages per second that can be exchanged between publishers and subscriber.
/// Measurements are performed for subscriptions containing no wildcard, a single wildcard or multiple wildcards.
/// </summary>
public class MessageThroughputTest
public sealed class MessageThroughputTest : IDisposable
{
// Change these constants to suit
const int NumPublishers = 5000;
@@ -55,9 +55,9 @@ public class MessageThroughputTest
await Setup();
await Subscribe_to_No_Wildcard_Topics();
await Subscribe_to_Single_Wildcard_Topics();
await Subscribe_to_Multi_Wildcard_Topics();
await SubscribeToNoWildcardTopics();
await SubscribeToSingleWildcardTopics();
await SubscribeToMultiWildcardTopics();
Console.WriteLine();
Console.WriteLine("End message throughput test");
@@ -74,7 +74,7 @@ public class MessageThroughputTest
public async Task Setup()
{
new TopicGenerator().Generate(NumPublishers, NumTopicsPerPublisher, out _topicsByPublisher, out _singleWildcardTopicsByPublisher, out _multiWildcardTopicsByPublisher);
TopicGenerator.Generate(NumPublishers, NumTopicsPerPublisher, out _topicsByPublisher, out _singleWildcardTopicsByPublisher, out _multiWildcardTopicsByPublisher);
var serverOptions = new MqttServerOptionsBuilder().WithDefaultEndpoint().Build();
var mqttClientFactory = new MqttClientFactory();
@@ -152,7 +152,7 @@ public class MessageThroughputTest
/// <summary>
/// Measure no-wildcard topic subscription message exchange performance
/// </summary>
public Task Subscribe_to_No_Wildcard_Topics()
public Task SubscribeToNoWildcardTopics()
{
return ProcessMessages(_topicsByPublisher, "no wildcards");
}
@@ -160,7 +160,7 @@ public class MessageThroughputTest
/// <summary>
/// Measure single-wildcard topic subscription message exchange performance
/// </summary>
public Task Subscribe_to_Single_Wildcard_Topics()
public Task SubscribeToSingleWildcardTopics()
{
return ProcessMessages(_singleWildcardTopicsByPublisher, "single wildcard");
}
@@ -168,7 +168,7 @@ public class MessageThroughputTest
/// <summary>
/// Measure multi-wildcard topic subscription message exchange performance
/// </summary>
public Task Subscribe_to_Multi_Wildcard_Topics()
public Task SubscribeToMultiWildcardTopics()
{
return ProcessMessages(_multiWildcardTopicsByPublisher, "multi wildcard");
}
@@ -342,4 +342,8 @@ public class MessageThroughputTest
Console.ResetColor();
}
public void Dispose()
{
_cancellationTokenSource.Dispose();
}
}
@@ -34,7 +34,9 @@ public static class MqttNetConsoleLogger
static void PrintToConsole(object sender, MqttNetLogMessagePublishedEventArgs e)
{
var output = new StringBuilder();
#pragma warning disable CA1305
output.AppendLine($">> [{e.LogMessage.Timestamp:O}] [{e.LogMessage.ThreadId}] [{e.LogMessage.Source}] [{e.LogMessage.Level}]: {e.LogMessage.Message}");
#pragma warning restore CA1305
if (e.LogMessage.Exception != null)
{
output.AppendLine(e.LogMessage.Exception.ToString());
+1 -1
View File
@@ -204,7 +204,7 @@ public static class PerformanceTest
};
}
static Task PublishSingleMessage(IMqttClient client, MqttApplicationMessage applicationMessage, ref int count)
static Task<MqttClientPublishResult> PublishSingleMessage(IMqttClient client, MqttApplicationMessage applicationMessage, ref int count)
{
Interlocked.Increment(ref count);
return Task.Run(() => client.PublishAsync(applicationMessage));
+1 -1
View File
@@ -85,7 +85,7 @@ public static class Program
}
else if (pressedKey.KeyChar == 'f')
{
Task.Run(new AsyncLockTest().Run);
Task.Run(AsyncLockTest.Run);
}
Thread.Sleep(Timeout.Infinite);
+1 -1
View File
@@ -157,7 +157,7 @@ public static class PublicBrokerTest
if (receivedMessage?.Topic != topic || receivedMessage?.ConvertPayloadToString() != "Hello_World")
{
throw new Exception("Message invalid.");
throw new InvalidOperationException("Message invalid.");
}
await client.UnsubscribeAsync(topic).ConfigureAwait(false);
+2 -2
View File
@@ -129,12 +129,12 @@ public static class ServerTest
mqttServer.InterceptingSubscriptionAsync += e =>
{
if (e.TopicFilter.Topic.StartsWith("admin/foo/bar") && e.ClientId != "theAdmin")
if (e.TopicFilter.Topic.StartsWith("admin/foo/bar", StringComparison.InvariantCulture) && e.ClientId != "theAdmin")
{
e.Response.ReasonCode = MqttSubscribeReasonCode.ImplementationSpecificError;
}
if (e.TopicFilter.Topic.StartsWith("the/secret/stuff") && e.ClientId != "Imperator")
if (e.TopicFilter.Topic.StartsWith("the/secret/stuff", StringComparison.InvariantCulture) && e.ClientId != "Imperator")
{
e.Response.ReasonCode = MqttSubscribeReasonCode.ImplementationSpecificError;
e.CloseConnection = true;
+4 -4
View File
@@ -6,7 +6,7 @@ namespace MQTTnet.TestApp;
public class TopicGenerator
{
public void Generate(
public static void Generate(
int numPublishers, int numTopicsPerPublisher,
out Dictionary<string, List<string>> topicsByPublisher,
out Dictionary<string, List<string>> singleWildcardTopicsByPublisher,
@@ -84,14 +84,14 @@ public class TopicGenerator
}
}
void AddPublisherTopic(string publisherName, string topic, Dictionary<string, List<string>> topicsByPublisher)
static void AddPublisherTopic(string publisherName, string topic, Dictionary<string, List<string>> topicsByPublisher)
{
List<string> topicList;
if (!topicsByPublisher.TryGetValue(publisherName, out topicList))
if (!topicsByPublisher.TryGetValue(publisherName, out var topicList))
{
topicList = new List<string>();
topicsByPublisher.Add(publisherName, topicList);
}
topicList.Add(topic);
}
}