コード例 #1
0
        public void TestMinimalPoolSizeIsEnsuredAtRuntime()
        {
            var builder = new MongoConnectionStringBuilder {
                MinimumPoolSize = 3, ConnectionLifetime = TimeSpan.FromMilliseconds(200)
            };

            using (var pool = new PooledConnectionFactory(builder.ToString()))
            {
                Assert.AreEqual(3, pool.PoolSize);

                Thread.Sleep(500); // ensure connection lifetime reached

                pool.Cleanup();

                Assert.AreEqual(3, pool.PoolSize);
            }
        }
コード例 #2
0
        public void TestCleanup()
        {
            var builder = new MongoConnectionStringBuilder
            {
                MinimumPoolSize    = 0,
                ConnectionLifetime = TimeSpan.FromMilliseconds(100)
            };

            using (var pool = new PooledConnectionFactory(builder.ToString()))
            {
                var connection1 = pool.Open();
                var connection2 = pool.Open();
                var connection3 = pool.Open();
                pool.Close(connection1);
                pool.Close(connection2);
                pool.Close(connection3);

                Thread.Sleep(300); // ensure lifetime reached

                pool.Cleanup();

                Assert.AreEqual(0, pool.PoolSize);
            }
        }