public void transient_exception_is_retried_but_throws_eventually()
        {
            using var conn = new NpgsqlConnection(ConnectionSource.ConnectionString);
            conn.Open();

            var retryPolicy          = DefaultRetryPolicy.Twice(sleep: x => TimeSpan.FromMilliseconds(20));
            var retryPolicyDecorator = RetryPolicyDecorator.For(retryPolicy, runNumber =>
                                                                throw createNpgsqlException(true));

            Should.Throw <NpgsqlException>(() => retryPolicyDecorator.Execute(() => conn.CreateCommand("").ExecuteNonQuery()));

            retryPolicyDecorator.ExecutionCount.ShouldBe(3);
        }
        public void non_transient_exception_is_not_retried()
        {
            using var conn = new NpgsqlConnection(ConnectionSource.ConnectionString);
            conn.Open();

            var retryPolicy          = DefaultRetryPolicy.Times(1, sleep: x => TimeSpan.FromMilliseconds(20));
            var retryPolicyDecorator = RetryPolicyDecorator.For(retryPolicy, runNumber =>
                                                                throw createNpgsqlException(false));

            Should.Throw <NpgsqlException>(() => retryPolicyDecorator.Execute(() => conn.CreateCommand().ExecuteNonQuery()));

            retryPolicyDecorator.ExecutionCount.ShouldBe(1);
        }
        public async Task transient_exception_is_retried()
        {
            using var conn = new NpgsqlConnection(ConnectionSource.ConnectionString);
            await conn.OpenAsync();

            var retryPolicy          = DefaultRetryPolicy.Times(1, sleep: x => TimeSpan.FromMilliseconds(20));
            var retryPolicyDecorator = RetryPolicyDecorator.For(retryPolicy, runNumber =>
            {
                if (runNumber == 1)
                {
                    throw createNpgsqlException(true);
                }
            });

            await retryPolicyDecorator.ExecuteAsync(() => conn.CreateCommand("select 1").ExecuteNonQueryAsync(), default);

            retryPolicyDecorator.ExecutionCount.ShouldBe(2);
        }