示例#1
0
        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));
        }
示例#2
0
        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);
        }