Stop existing sessions before takeover from another client.

This commit is contained in:
Christian Kratky
2018-12-02 21:50:16 +01:00
parent fdb2ec897c
commit 86c348df58
8 changed files with 152 additions and 85 deletions
@@ -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)
{