public async Task TestDoesNotShareDifferentConnections() { var pool = new ZooKeeperConnection.Pool(maxAge: TimeSpan.FromSeconds(10)); using var connection1 = await pool.ConnectAsync(GetConnectionInfo (connectTimeout : TimeSpan.FromSeconds(30)), CancellationToken.None); using var connection2 = await pool.ConnectAsync(GetConnectionInfo (connectTimeout : TimeSpan.FromSeconds(20)), CancellationToken.None); Assert.AreNotSame(connection1, connection2); Assert.AreNotSame(connection1.ZooKeeper, connection2.ZooKeeper); }
public async Task TestSharesConnections() { var pool = new ZooKeeperConnection.Pool(maxAge: TimeSpan.FromSeconds(10)); using var connection1 = await pool.ConnectAsync(GetConnectionInfo (), CancellationToken.None); using var connection2 = await pool.ConnectAsync(GetConnectionInfo (), CancellationToken.None); Assert.AreNotSame(connection1, connection2); Assert.AreSame(connection1.ZooKeeper, connection2.ZooKeeper); connection1.Dispose(); connection2.ZooKeeper.getState().ShouldEqual(ZooKeeper.States.CONNECTED); }
[NonParallelizable, Retry(tryCount: 3)] // timing-sensitive public async Task TestConnectionIsClosedAndNotSharedAfterMaxAgeElapses() { var pool = new ZooKeeperConnection.Pool(maxAge: TimeSpan.FromSeconds(2)); using var connection1 = await pool.ConnectAsync(GetConnectionInfo (), CancellationToken.None); var zooKeeper1 = connection1.ZooKeeper; connection1.Dispose(); Assert.IsTrue(await TestHelper.WaitForAsync(() => (zooKeeper1.getState() == ZooKeeper.States.CLOSED).AsValueTask(), TimeSpan.FromSeconds(3))); using var connection2 = await pool.ConnectAsync(GetConnectionInfo (), CancellationToken.None); Assert.AreNotSame(zooKeeper1, connection2.ZooKeeper); }
[NonParallelizable, Retry(tryCount: 3)] // timing-sensitive public async Task TestConnectionCanBeHeldOpenAfterMaxAgeButDoesNotShareAndClosesAfterwards() { var pool = new ZooKeeperConnection.Pool(maxAge: TimeSpan.FromSeconds(2)); using var connection = await pool.ConnectAsync(GetConnectionInfo (), CancellationToken.None); Assert.IsTrue(await TestHelper.WaitForAsync( async() => { using var testConnectionInfo = await pool.ConnectAsync(GetConnectionInfo(), CancellationToken.None); return(testConnectionInfo.ZooKeeper != connection.ZooKeeper); }, TimeSpan.FromSeconds(3) )); connection.ZooKeeper.getState().ShouldEqual(ZooKeeper.States.CONNECTED); var zooKeeper = connection.ZooKeeper; connection.Dispose(); Assert.IsTrue(await TestHelper.WaitForAsync(() => (zooKeeper.getState() != ZooKeeper.States.CONNECTED).AsValueTask(), TimeSpan.FromSeconds(1))); }
[NonParallelizable, Retry(tryCount: 3)] // timing-sensitive public void TestConnectTimeout() { var pool = new ZooKeeperConnection.Pool(maxAge: TimeSpan.FromSeconds(10)); Assert.ThrowsAsync <TimeoutException>(() => pool.ConnectAsync(GetConnectionInfo(connectTimeout: TimeSpan.Zero), CancellationToken.None)); }