|
|
@@ -484,6 +484,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>(); |
|
|
|