Npgsql.Tests.ConnectionTests.Keepalive C# (CSharp) Method

Keepalive() private method

private Keepalive ( ) : void
return void
        public void Keepalive()
        {
            var csbWithKeepAlive = new NpgsqlConnectionStringBuilder(ConnectionString) { KeepAlive = 1 };
            var mre = new ManualResetEvent(false);
            using (var conn1 = OpenConnection())
            using (var conn2 = OpenConnection(csbWithKeepAlive))
            {
                conn2.StateChange += (sender, args) =>
                {
                    if (args.CurrentState == ConnectionState.Closed)
                        mre.Set();
                };

                // Use another connection to kill our keepalive connection
                conn1.ExecuteNonQuery($"SELECT pg_terminate_backend({conn2.ProcessID})");
                mre.WaitOne();
                Assert.That(conn2.State, Is.EqualTo(ConnectionState.Closed));
                Assert.That(conn2.FullState, Is.EqualTo(ConnectionState.Broken));
            }
        }