public async Task DoesNotThrowWithLateReturns() { var memoryPool = new DiagnosticMemoryPool(new PinnedBlockMemoryPool(), allowLateReturn: true); var block = memoryPool.Rent(); memoryPool.Dispose(); block.Dispose(); await memoryPool.WhenAllBlocksReturnedAsync(TimeSpan.FromSeconds(5)); }
public void ExceptionsContainStackTraceWhenEnabled() { var memoryPool = new DiagnosticMemoryPool(new PinnedBlockMemoryPool(), rentTracking: true); var block = memoryPool.Rent(); ExpectDisposeException(memoryPool); var exception = Assert.Throws <InvalidOperationException>(() => block.Memory); Assert.Contains("Block is backed by disposed slab", exception.Message); Assert.Contains("ExceptionsContainStackTraceWhenEnabled", exception.Message); }
public async Task ThrowsOnAccessToLateBlocks() { var memoryPool = new DiagnosticMemoryPool(new PinnedBlockMemoryPool(), allowLateReturn: true); var block = memoryPool.Rent(); memoryPool.Dispose(); var exception = Assert.Throws <InvalidOperationException>(() => block.Memory); Assert.Equal("Block is backed by disposed slab", exception.Message); block.Dispose(); var aggregateException = await Assert.ThrowsAsync <AggregateException>(async() => await memoryPool.WhenAllBlocksReturnedAsync(TimeSpan.FromSeconds(5))); Assert.Equal(new Exception [] { exception }, aggregateException.InnerExceptions); }