improved timeout after memory usage

This commit is contained in:
Eggers Jan
2017-09-20 09:33:41 +02:00
parent f287bd4d1d
commit b5b87f5272
2 changed files with 71 additions and 75 deletions
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Core.Exceptions;
@@ -67,5 +68,23 @@ namespace MQTTnet.Core.Tests
Assert.IsTrue(e.InnerException is IndexOutOfRangeException);
}
}
[TestMethod]
public async Task TimeoutAfterMemoryUsage()
{
var tasks = Enumerable.Range(0, 100000)
.Select(i => Task.Delay(TimeSpan.FromMilliseconds(1)).TimeoutAfter(TimeSpan.FromMinutes(1)));
await Task.WhenAll( tasks );
AssertIsLess( 3_000_000, GC.GetTotalMemory( true ) );
}
private void AssertIsLess( long bound, long actual )
{
if ( bound < actual )
{
Assert.Fail( $"value must be less than {bound:N0} but is {actual:N0}" );
}
}
}
}