public async Task MaxPoolSizeNotViolated() { using (var pool = new SessionPool()) { pool.Options.MaximumPooledSessions = 2; var client = CreateMockClient(); var sessions = await Task.WhenAll( pool.CreateSessionFromPoolAsync( client.Object, s_defaultName.ProjectId, s_defaultName.InstanceId, s_defaultName.DatabaseId, null, CancellationToken.None), pool.CreateSessionFromPoolAsync( client.Object, s_defaultName.ProjectId, s_defaultName.InstanceId, s_defaultName.DatabaseId, null, CancellationToken.None), pool.CreateSessionFromPoolAsync( client.Object, s_defaultName.ProjectId, s_defaultName.InstanceId, s_defaultName.DatabaseId, null, CancellationToken.None)) .ConfigureAwait(false); pool.ReleaseToPool(client.Object, sessions[0]); pool.ReleaseToPool(client.Object, sessions[1]); pool.ReleaseToPool(client.Object, sessions[2]); Assert.Equal( 2, pool.GetPoolSize( client.Object, s_defaultName.ProjectId, s_defaultName.InstanceId, s_defaultName.DatabaseId)); } }
public async Task MaxPoolSizeNotViolated() { using (var pool = new SessionPool()) { pool.Options.MaximumPooledSessions = 2; var client = new FakeClient(); var sessions = await Task.WhenAll( CreateSessionAsync(pool, client), CreateSessionAsync(pool, client), CreateSessionAsync(pool, client)); pool.ReleaseToPool(client, sessions[0]); pool.ReleaseToPool(client, sessions[1]); pool.ReleaseToPool(client, sessions[2]); var actualSize = pool.GetPoolSize(client, s_defaultName.ProjectId, s_defaultName.InstanceId, s_defaultName.DatabaseId); Assert.Equal(2, actualSize); } }