mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 19:58:57 +08:00
Start migration of server to new packet bus.
This commit is contained in:
@@ -10,6 +10,7 @@ using MQTTnet.Client;
|
||||
using MQTTnet.Client.Connecting;
|
||||
using MQTTnet.Client.Disconnecting;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Client.Publishing;
|
||||
using MQTTnet.Client.Receiving;
|
||||
using MQTTnet.Client.Subscribing;
|
||||
using MQTTnet.Exceptions;
|
||||
@@ -870,5 +871,83 @@ namespace MQTTnet.Tests.Client
|
||||
Assert.IsFalse(disconnectedFired);
|
||||
}
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(MqttQualityOfServiceLevel.ExactlyOnce)]
|
||||
[DataRow(MqttQualityOfServiceLevel.AtMostOnce)]
|
||||
[DataRow(MqttQualityOfServiceLevel.AtLeastOnce)]
|
||||
public async Task Concurrent_Processing(MqttQualityOfServiceLevel qos)
|
||||
{
|
||||
long concurrency = 0;
|
||||
bool success = false;
|
||||
|
||||
using (var testEnvironment = new TestEnvironment(TestContext))
|
||||
{
|
||||
await testEnvironment.StartServer();
|
||||
var publisher = await testEnvironment.ConnectClient();
|
||||
var subscriber = await testEnvironment.ConnectClient(new MqttClientOptionsBuilder().WithClientId(qos.ToString()));
|
||||
await subscriber.SubscribeAsync("#", qos);
|
||||
|
||||
subscriber.UseApplicationMessageReceivedHandler(c =>
|
||||
{
|
||||
c.AutoAcknowledge = false;
|
||||
|
||||
async Task InvokeInternal()
|
||||
{
|
||||
if (Interlocked.Increment(ref concurrency) > 1) success = true;
|
||||
await Task.Delay(100);
|
||||
Interlocked.Decrement(ref concurrency);
|
||||
}
|
||||
|
||||
_ = InvokeInternal();
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
var publishes = Task.WhenAll(
|
||||
publisher.PublishAsync("a", null, qos),
|
||||
publisher.PublishAsync("b", null, qos)
|
||||
);
|
||||
|
||||
await Task.Delay(200);
|
||||
|
||||
await publishes;
|
||||
Assert.IsTrue(success);
|
||||
}
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(MqttQualityOfServiceLevel.ExactlyOnce)]
|
||||
[DataRow(MqttQualityOfServiceLevel.AtLeastOnce)]
|
||||
public async Task Retry_If_Not_PubAck(MqttQualityOfServiceLevel qos)
|
||||
{
|
||||
long count = 0;
|
||||
using (var testEnvironment = new TestEnvironment(TestContext))
|
||||
{
|
||||
await testEnvironment.StartServer();
|
||||
var publisher = await testEnvironment.ConnectClient();
|
||||
var subscriber = await testEnvironment.ConnectClient(new MqttClientOptionsBuilder().WithClientId(qos.ToString()));
|
||||
await subscriber.SubscribeAsync("#", qos);
|
||||
|
||||
subscriber.UseApplicationMessageReceivedHandler(c =>
|
||||
{
|
||||
c.AutoAcknowledge = false;
|
||||
++count;
|
||||
Console.WriteLine("process");
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
var pub = publisher.PublishAsync("a", null, qos);
|
||||
|
||||
await Task.Delay(100);
|
||||
await subscriber.DisconnectAsync();
|
||||
await subscriber.ReconnectAsync();
|
||||
await Task.Delay(100);
|
||||
|
||||
var res = await pub;
|
||||
|
||||
Assert.AreEqual(MqttClientPublishReasonCode.Success, res.ReasonCode);
|
||||
Assert.AreEqual(2, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user