mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-11-04 13:33:02 +08:00
Stop existing sessions before takeover from another client.
This commit is contained in:
@@ -228,6 +228,39 @@ namespace MQTTnet.Core.Tests
|
||||
|
||||
Assert.AreEqual(2000, receivedMessagesCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task MqttServer_SessionTakeover()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
|
||||
var client1 = new MqttFactory().CreateMqttClient();
|
||||
var client2 = new MqttFactory().CreateMqttClient();
|
||||
|
||||
var options = new MqttClientOptionsBuilder()
|
||||
.WithTcpServer("localhost")
|
||||
.WithCleanSession(false)
|
||||
.WithClientId("a").Build();
|
||||
|
||||
await client1.ConnectAsync(options);
|
||||
|
||||
await Task.Delay(500);
|
||||
|
||||
await client2.ConnectAsync(options);
|
||||
|
||||
await Task.Delay(500);
|
||||
|
||||
Assert.IsFalse(client1.IsConnected);
|
||||
Assert.IsTrue(client2.IsConnected);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task Publish(IMqttClient c1, MqttApplicationMessage message)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user