mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 11:45:43 +08:00
prove its broken
This commit is contained in:
@@ -25,8 +25,8 @@ namespace MQTTnet.Client
|
|||||||
|
|
||||||
private IMqttClientOptions _options;
|
private IMqttClientOptions _options;
|
||||||
private CancellationTokenSource _cancellationTokenSource;
|
private CancellationTokenSource _cancellationTokenSource;
|
||||||
private Task _packetReceiverTask;
|
internal Task _packetReceiverTask;
|
||||||
private Task _keepAliveMessageSenderTask;
|
internal Task _keepAliveMessageSenderTask;
|
||||||
private IMqttChannelAdapter _adapter;
|
private IMqttChannelAdapter _adapter;
|
||||||
private bool _cleanDisconnectInitiated;
|
private bool _cleanDisconnectInitiated;
|
||||||
private TaskCompletionSource<bool> _disconnectReason;
|
private TaskCompletionSource<bool> _disconnectReason;
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
[assembly:InternalsVisibleTo("MQTTnet.Core.Tests")]
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using MQTTnet.Adapter;
|
||||||
using MQTTnet.Client;
|
using MQTTnet.Client;
|
||||||
|
using MQTTnet.Diagnostics;
|
||||||
using MQTTnet.Exceptions;
|
using MQTTnet.Exceptions;
|
||||||
|
using MQTTnet.Packets;
|
||||||
|
|
||||||
namespace MQTTnet.Core.Tests
|
namespace MQTTnet.Core.Tests
|
||||||
{
|
{
|
||||||
@@ -35,5 +39,37 @@ namespace MQTTnet.Core.Tests
|
|||||||
Assert.IsInstanceOfType(ex, typeof(MqttCommunicationException));
|
Assert.IsInstanceOfType(ex, typeof(MqttCommunicationException));
|
||||||
Assert.IsInstanceOfType(ex.InnerException, typeof(SocketException));
|
Assert.IsInstanceOfType(ex.InnerException, typeof(SocketException));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task ClientCleanupOnAuthentificationFails()
|
||||||
|
{
|
||||||
|
var channel = new TestMqttCommunicationAdapter();
|
||||||
|
var channel2 = new TestMqttCommunicationAdapter();
|
||||||
|
channel.Partner = channel2;
|
||||||
|
channel2.Partner = channel;
|
||||||
|
|
||||||
|
Task.Run(async () => {
|
||||||
|
var connect = await channel2.ReceivePacketAsync(TimeSpan.Zero, CancellationToken.None);
|
||||||
|
await channel2.SendPacketAsync(new MqttConnAckPacket() { ConnectReturnCode = Protocol.MqttConnectReturnCode.ConnectionRefusedNotAuthorized }, CancellationToken.None);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var fake = new TestMqttCommunicationAdapterFactory(channel);
|
||||||
|
|
||||||
|
var client = new MqttClient(fake, new MqttNetLogger());
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("any-server").Build());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Assert.IsInstanceOfType(ex, typeof(MqttConnectingFailedException));
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.IsTrue(client._packetReceiverTask == null || client._packetReceiverTask.IsCompleted, "receive loop not completed");
|
||||||
|
Assert.IsTrue(client._keepAliveMessageSenderTask == null || client._keepAliveMessageSenderTask.IsCompleted, "keepalive loop not completed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user