Преглед изворни кода

Improve unit tests.

release/3.x.x
Christian Kratky пре 4 година
родитељ
комит
cf7e59a774
3 измењених фајлова са 11 додато и 4 уклоњено
  1. +8
    -1
      Source/MQTTnet/Implementations/CrossPlatformSocket.cs
  2. +2
    -2
      Tests/MQTTnet.Core.Tests/MqttTcpChannel_Tests.cs
  3. +1
    -1
      Tests/MQTTnet.Core.Tests/Server_Tests.cs

+ 8
- 1
Source/MQTTnet/Implementations/CrossPlatformSocket.cs Прегледај датотеку

@@ -10,6 +10,8 @@ namespace MQTTnet.Implementations
{
readonly Socket _socket;

NetworkStream _networkStream;

public CrossPlatformSocket(AddressFamily addressFamily)
{
_socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp);
@@ -137,6 +139,8 @@ namespace MQTTnet.Implementations

try
{
_networkStream?.Dispose();

// Workaround for: workaround for https://github.com/dotnet/corefx/issues/24430
using (cancellationToken.Register(() => _socket.Dispose()))
{
@@ -148,6 +152,8 @@ namespace MQTTnet.Implementations
await _socket.ConnectAsync(host, port).ConfigureAwait(false);
#endif
}

_networkStream = new NetworkStream(_socket, true);
}
catch (ObjectDisposedException)
{
@@ -190,11 +196,12 @@ namespace MQTTnet.Implementations

public NetworkStream GetStream()
{
return new NetworkStream(_socket, true);
return _networkStream;
}

public void Dispose()
{
_networkStream?.Dispose();
_socket?.Dispose();
}



+ 2
- 2
Tests/MQTTnet.Core.Tests/MqttTcpChannel_Tests.cs Прегледај датотеку

@@ -37,10 +37,10 @@ namespace MQTTnet.Tests
var clientSocket = new CrossPlatformSocket(AddressFamily.InterNetwork);
await clientSocket.ConnectAsync("localhost", 50001, CancellationToken.None);

await Task.Delay(100, ct.Token);

var tcpChannel = new MqttTcpChannel(clientSocket.GetStream(), "test", null);

await Task.Delay(100, ct.Token);

var buffer = new byte[1];
await tcpChannel.ReadAsync(buffer, 0, 1, ct.Token);



+ 1
- 1
Tests/MQTTnet.Core.Tests/Server_Tests.cs Прегледај датотеку

@@ -375,7 +375,7 @@ namespace MQTTnet.Tests
await c1.PublishAsync(message);
}

await Task.Delay(500);
await Task.Delay(3000);

Assert.AreEqual(2000, receivedMessagesCount);
}


Loading…
Откажи
Сачувај