예제 #1
0
        public async Task Dispose_VerifyAllSharedMemoryResourcesFreed()
        {
            // Prepare content
            string invocationId1 = Guid.NewGuid().ToString();
            string invocationId2 = Guid.NewGuid().ToString();
            string content       = "foobar";

            SharedMemoryManager manager = new SharedMemoryManager(_loggerFactory, _mapAccessor);

            // Put content into shared memory and add mapping to invocations
            SharedMemoryMetadata metadata1 = await manager.PutObjectAsync(content);

            string mapName1 = metadata1.MemoryMapName;

            manager.AddSharedMemoryMapForInvocation(invocationId1, mapName1);
            SharedMemoryMetadata metadata2 = await manager.PutObjectAsync(content);

            string mapName2 = metadata2.MemoryMapName;

            manager.AddSharedMemoryMapForInvocation(invocationId2, mapName2);

            // Open the shared memory map; should open
            Assert.True(_mapAccessor.TryOpen(mapName1, out MemoryMappedFile mmf1));
            Assert.True(_mapAccessor.TryOpen(mapName1, out MemoryMappedFile mmf2));
            mmf1.Dispose();
            mmf2.Dispose();

            // Dispose the shared memory manager; all shared memory maps it was tracking should be freed
            manager.Dispose();

            // Open the shared memory map; should not open
            Assert.False(_mapAccessor.TryOpen(mapName1, out _));
            Assert.False(_mapAccessor.TryOpen(mapName1, out _));
        }