Merge branch 'develop' into ServerShutdown

This commit is contained in:
Christian
2018-07-26 14:45:25 +02:00
committed by GitHub
16 changed files with 277 additions and 86 deletions
@@ -552,6 +552,54 @@ namespace MQTTnet.Core.Tests
Assert.IsTrue(bodyIsMatching);
}
[TestMethod]
public async Task MqttServer_SameClientIdConnectDisconnectEventOrder()
{
var serverAdapter = new MqttTcpServerAdapter(new MqttNetLogger().CreateChildLogger());
var s = new MqttFactory().CreateMqttServer(new[] { serverAdapter }, new MqttNetLogger());
var connectedClient = false;
var connecteCalledBeforeConnectedClients = false;
s.ClientConnected += (_, __) =>
{
connecteCalledBeforeConnectedClients |= connectedClient;
connectedClient = true;
};
s.ClientDisconnected += (_, __) =>
{
connectedClient = false;
};
var clientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("localhost")
.WithClientId(Guid.NewGuid().ToString())
.Build();
await s.StartAsync(new MqttServerOptions());
var c1 = new MqttFactory().CreateMqttClient();
var c2 = new MqttFactory().CreateMqttClient();
await c1.ConnectAsync(clientOptions);
await Task.Delay(100);
await c2.ConnectAsync(clientOptions);
await Task.Delay(100);
await c1.DisconnectAsync();
await c2.DisconnectAsync();
await s.StopAsync();
await Task.Delay(100);
Assert.IsFalse(connecteCalledBeforeConnectedClients, "ClientConnected was called before ClientDisconnect was called");
}
private class TestStorage : IMqttServerStorage
{
public IList<MqttApplicationMessage> Messages = new List<MqttApplicationMessage>();