Remove not used timeout for receiving.

This commit is contained in:
Christian Kratky
2020-11-02 21:45:23 +01:00
parent 44b7133a1c
commit fb2be79673
15 changed files with 49 additions and 42 deletions
@@ -34,7 +34,7 @@ namespace MQTTnet.AspNetCore.Tests
pipe.Receive.Writer.Complete();
await Assert.ThrowsExceptionAsync<MqttCommunicationException>(() => ctx.ReceivePacketAsync(TimeSpan.Zero, CancellationToken.None));
await Assert.ThrowsExceptionAsync<MqttCommunicationException>(() => ctx.ReceivePacketAsync(CancellationToken.None));
}
[TestMethod]
@@ -49,10 +49,10 @@ namespace MQTTnet.AspNetCore.Tests
await pipe.Receive.Writer.WriteAsync(writer.AddMqttHeader(MqttControlPacketType.Connect, new byte[0]));
await Assert.ThrowsExceptionAsync<MqttProtocolViolationException>(() => ctx.ReceivePacketAsync(TimeSpan.Zero, CancellationToken.None));
await Assert.ThrowsExceptionAsync<MqttProtocolViolationException>(() => ctx.ReceivePacketAsync(CancellationToken.None));
// the first exception should complete the pipes so if someone tries to use the connection after that it should throw immidiatly
await Assert.ThrowsExceptionAsync<InvalidOperationException>(() => ctx.ReceivePacketAsync(TimeSpan.Zero, CancellationToken.None));
await Assert.ThrowsExceptionAsync<InvalidOperationException>(() => ctx.ReceivePacketAsync(CancellationToken.None));
}
// COMMENTED OUT DUE TO DEAD LOCK? OR VERY VERY SLOW PERFORMANCE ON LOCAL DEV MACHINE. TEST WAS STILL RUNNING AFTER SEVERAL MINUTES!
@@ -53,7 +53,7 @@ namespace MQTTnet.Benchmarks
for (var i = 0; i < 10000; i++)
{
_channelAdapter.ReceivePacketAsync(TimeSpan.Zero, CancellationToken.None).GetAwaiter().GetResult();
_channelAdapter.ReceivePacketAsync(CancellationToken.None).GetAwaiter().GetResult();
}
_stream.Position = 0;
@@ -169,6 +169,7 @@ namespace MQTTnet.Tests.Mockups
{
foreach (var mqttClient in _clients)
{
mqttClient.DisconnectAsync().GetAwaiter().GetResult();
mqttClient?.Dispose();
}
@@ -51,7 +51,7 @@ namespace MQTTnet.Tests.Mockups
return Task.FromResult(0);
}
public Task<MqttBasePacket> ReceivePacketAsync(TimeSpan timeout, CancellationToken cancellationToken)
public Task<MqttBasePacket> ReceivePacketAsync(CancellationToken cancellationToken)
{
ThrowIfPartnerIsNull();
@@ -161,6 +161,8 @@ namespace MQTTnet.Tests
SpinWait.SpinUntil(() => replyReceived, TimeSpan.FromSeconds(10));
await Task.Delay(500);
Assert.IsTrue(replyReceived);
}
}
@@ -21,6 +21,7 @@ namespace MQTTnet.Tests
var client = await testEnvironment.ConnectLowLevelClientAsync(o => o
.WithCommunicationTimeout(TimeSpan.FromSeconds(1))
.WithCommunicationTimeout(TimeSpan.Zero)
.WithProtocolVersion(MqttProtocolVersion.V500)).ConfigureAwait(false);
await client.SendAsync(new MqttConnectPacket
@@ -35,17 +36,18 @@ namespace MQTTnet.Tests
for (var i = 0; i < 6; i++)
{
await client.SendAsync(MqttPingReqPacket.Instance, CancellationToken.None);
await Task.Delay(500);
await client.SendAsync(MqttPingReqPacket.Instance, CancellationToken.None);
responsePacket = await client.ReceiveAsync(CancellationToken.None);
Assert.IsTrue(responsePacket is MqttPingRespPacket);
}
// If we reach this point everything works as expected (server did not close the connection
// due to proper ping messages.
// Now we will wait 1.2 seconds because the server MUST wait 1.5 seconds in total (See spec).
// Now we will wait 1.1 seconds because the server MUST wait 1.5 seconds in total (See spec).
await Task.Delay(1200);
await Task.Delay(1100);
await client.SendAsync(MqttPingReqPacket.Instance, CancellationToken.None);
responsePacket = await client.ReceiveAsync(CancellationToken.None);
Assert.IsTrue(responsePacket is MqttPingRespPacket);
+2 -4
View File
@@ -96,9 +96,7 @@ namespace MQTTnet.Tests
var serverOptions = new MqttServerOptionsBuilder();
await testEnvironment.StartServerAsync(serverOptions);
var options = new MqttClientOptionsBuilder()
.WithClientId("1")
;
var options = new MqttClientOptionsBuilder().WithClientId("1");
var clients = await Task.WhenAll(Enumerable.Range(0, 10)
.Select(i => TryConnect(testEnvironment, options)));
@@ -109,7 +107,7 @@ namespace MQTTnet.Tests
}
}
private async Task<IMqttClient> TryConnect(TestEnvironment testEnvironment, MqttClientOptionsBuilder options)
async Task<IMqttClient> TryConnect(TestEnvironment testEnvironment, MqttClientOptionsBuilder options)
{
try
{