public void Dispose() { foreach (DisplayList displayList in RenderQueue) { displayList.Dispose(); } Pool.Dispose(); WIP.Dispose(); }
public async Task CreateFailsAfterDispose() { var capacity = 2; var context = new Context(TestGlobal.Logger); var pool = new ResourcePool <Key, Resource>(context, maxResourceCount: capacity, maxAgeMinutes: 1, resourceFactory: _ => new Resource()); pool.Dispose(); await Assert.ThrowsAsync <ObjectDisposedException>(async() => { using var obj1 = await pool.CreateAsync(new Key(0)); }); }
public void TestPoolThrowsExceptionIfResourcesInUse() { var resources = 0; var factoryMock = new Mock <IStringFactory>(); factoryMock.Setup(x => x.GetString()) .Returns(() => resources++ < 5 ? Guid.NewGuid().ToString() : null); var pool = new ResourcePool <string>(x => factoryMock.Object.GetString()); var item = pool.GetItem(); Assert.Throws <InvalidOperationException>(() => pool.Dispose()); }
public void Dispose() { if (_rpool == null) { return; } lock (this) { if (_rpool != null) { _rpool.Dispose(); _rpool = null; } } }
public Task CreateFailsAfterDispose() { var capacity = 2; var context = new Context(TestGlobal.Logger); var pool = new ResourcePool <Key, Resource>(context, new ResourcePoolConfiguration() { MaximumResourceCount = capacity, MaximumAge = TimeSpan.FromMinutes(1), }, resourceFactory: _ => new Resource()); pool.Dispose(); return(Assert.ThrowsAsync <ObjectDisposedException>(async() => { using var obj1 = await pool.CreateAsync(new Key(0)); })); }
public void ResourceHandle_should_cancel_instance_creation_upon_pool_disposal() { async Task <IDisposable> FactoryMethod(CancellationToken token) { await Task.Delay(2000, token); Assert.Fail("Factory method not get cancelled before reaching here"); return(null); } using (var pool = new ResourcePool <IDisposable>(FactoryMethod, 1)) { var handle = pool.CreateHandle(); var task = handle.ObtainAsync(); pool.Dispose(); Assert.ThrowsAsync <TaskCanceledException>(async() => await task); } }
private static async Task RunTest <TKey, TObject>(Func <OperationContext, ResourcePool <TKey, TObject>, Task> func, Func <TKey, TObject> factory, ResourcePoolConfiguration?configuration = null, IClock?clock = null) where TKey : notnull where TObject : IStartupShutdownSlim { configuration ??= new ResourcePoolConfiguration(); var tracingContext = new Context(TestGlobal.Logger); var context = new OperationContext(tracingContext); var pool = new ResourcePool <TKey, TObject>(tracingContext, configuration, factory, clock); try { await func(context, pool); } finally { pool.Dispose(); ValidateCounters(pool.Counter); } }
protected override Task <BoolResult> ShutdownCoreAsync(OperationContext context) { _pool.Dispose(); return(base.ShutdownCoreAsync(context)); }
/// <inheritdoc /> public void Dispose() { _resourcePool?.Dispose(); }