mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 11:45:43 +08:00
unfifed timeout handling and fixed memory usage due to Task.Delay tasks for each send package are present for the duration of the timeout resulting in memory usage. new approach uses cancellationtoken that will be cleaned up directly if operation completes before timeout
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Core.Exceptions;
|
||||
using MQTTnet.Core.Internal;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class ExtensionTests
|
||||
{
|
||||
[ExpectedException(typeof( MqttCommunicationTimedOutException ) )]
|
||||
[TestMethod]
|
||||
public async Task TestTimeoutAfter()
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(500)).TimeoutAfter(TimeSpan.FromMilliseconds(100));
|
||||
}
|
||||
|
||||
[ExpectedException(typeof( MqttCommunicationTimedOutException))]
|
||||
[TestMethod]
|
||||
public async Task TestTimeoutAfterWithResult()
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(500)).ContinueWith(t => 5).TimeoutAfter(TimeSpan.FromMilliseconds(100));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestTimeoutAfterCompleteInTime()
|
||||
{
|
||||
var result = await Task.Delay( TimeSpan.FromMilliseconds( 100 ) ).ContinueWith( t => 5 ).TimeoutAfter( TimeSpan.FromMilliseconds( 500 ) );
|
||||
Assert.AreEqual( 5, result );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="ByteReaderTests.cs" />
|
||||
<Compile Include="ByteWriterTests.cs" />
|
||||
<Compile Include="ExtensionTests.cs" />
|
||||
<Compile Include="MqttPacketSerializerTests.cs" />
|
||||
<Compile Include="MqttServerTests.cs" />
|
||||
<Compile Include="MqttSubscriptionsManagerTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user