Beispiel #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));
        }
Beispiel #2
0
        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);
        }
Beispiel #3
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);
        }