<commit_before>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LinearBackOffTest.cs">
//   Copyright (c) 2017. All rights reserved.
//   Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
// <auto-generated>
//   Sourced from NuGet package. Will be overwritten with package update except in Spritely.Redo source.
// </auto-generated>
// --------------------------------------------------------------------------------------------------------------------

namespace Spritely.Redo.Test
{
    using System;
    using System.Diagnostics;
    using FluentAssertions;
    using Xunit;

    public class LinearBackOffTest
    {
        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_once_with_overload_1()
        {
            var times = 0;
            var expectedDelay = TimeSpan.FromMilliseconds(150);
            var retriableOperation = Using.LinearBackOff(expectedDelay).Run(
                () =>
                {
                    times++;
                    if (times > 1)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 50);
            times.Should().Be(2); // 1 failure + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_once_with_overload_2()
        {
            var times = 0;
            var expectedDelay = TimeSpan.FromMilliseconds(150);
            var retriableOperation = Using.LinearBackOff(expectedDelay, TimeSpan.FromSeconds(5)).Run(
                () =>
                {
                    times++;
                    if (times > 1)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 50);
            times.Should().Be(2); // 1 failure + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_twice_with_overload_1()
        {
            var times = 0;
            var delay = TimeSpan.FromMilliseconds(100);
            var expectedDelay = TimeSpan.FromMilliseconds(300); // 100 + 200
            var retriableOperation = Using.LinearBackOff(delay).Run(
                () =>
                {
                    times++;
                    if (times > 2)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 75);
            times.Should().Be(3); // 2 failures + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_twice_with_overload_2()
        {
            var times = 0;
            var delay = TimeSpan.FromMilliseconds(100);
            var delta = TimeSpan.FromMilliseconds(50);
            var expectedDelay = TimeSpan.FromMilliseconds(250); // 100 + 150
            var retriableOperation = Using.LinearBackOff(delay, delta).Run(
                () =>
                {
                    times++;
                    if (times > 2)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 75);
            times.Should().Be(3); // 2 failures + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_five_times_with_overload_1()
        {
            var times = 0;
            var delay = TimeSpan.FromMilliseconds(50);
            var expectedDelay = TimeSpan.FromMilliseconds(750); // 50 + 100 + 150 + 200 + 250
            var retriableOperation = Using.LinearBackOff(delay).Run(
                () =>
                {
                    times++;
                    if (times > 5)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 150);
            times.Should().Be(6); // 5 failures + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_five_times_with_overload_2()
        {
            var times = 0;
            var delay = TimeSpan.FromMilliseconds(50);
            var delta = TimeSpan.FromMilliseconds(20);
            var expectedDelay = TimeSpan.FromMilliseconds(540); // 50 + 70 + 90 + 110 + 120
            var retriableOperation = Using.LinearBackOff(delay, delta).Run(
                () =>
                {
                    times++;
                    if (times > 5)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 150);
            times.Should().Be(6); // 5 failures + 1 success
        }
    }
}
<commit_msg>Allow more generous time variation in test<commit_after>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LinearBackOffTest.cs">
//   Copyright (c) 2017. All rights reserved.
//   Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
// <auto-generated>
//   Sourced from NuGet package. Will be overwritten with package update except in Spritely.Redo source.
// </auto-generated>
// --------------------------------------------------------------------------------------------------------------------

namespace Spritely.Redo.Test
{
    using System;
    using System.Diagnostics;
    using FluentAssertions;
    using Xunit;

    public class LinearBackOffTest
    {
        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_once_with_overload_1()
        {
            var times = 0;
            var expectedDelay = TimeSpan.FromMilliseconds(150);
            var retriableOperation = Using.LinearBackOff(expectedDelay).Run(
                () =>
                {
                    times++;
                    if (times > 1)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 50);
            times.Should().Be(2); // 1 failure + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_once_with_overload_2()
        {
            var times = 0;
            var expectedDelay = TimeSpan.FromMilliseconds(150);
            var retriableOperation = Using.LinearBackOff(expectedDelay, TimeSpan.FromSeconds(5)).Run(
                () =>
                {
                    times++;
                    if (times > 1)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 50);
            times.Should().Be(2); // 1 failure + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_twice_with_overload_1()
        {
            var times = 0;
            var delay = TimeSpan.FromMilliseconds(100);
            var expectedDelay = TimeSpan.FromMilliseconds(300); // 100 + 200
            var retriableOperation = Using.LinearBackOff(delay).Run(
                () =>
                {
                    times++;
                    if (times > 2)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 75);
            times.Should().Be(3); // 2 failures + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_twice_with_overload_2()
        {
            var times = 0;
            var delay = TimeSpan.FromMilliseconds(500);
            var delta = TimeSpan.FromMilliseconds(250);
            var expectedDelay = TimeSpan.FromMilliseconds(1250); // 500 + 750
            var retriableOperation = Using.LinearBackOff(delay, delta).Run(
                () =>
                {
                    times++;
                    if (times > 2)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 150);
            times.Should().Be(3); // 2 failures + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_five_times_with_overload_1()
        {
            var times = 0;
            var delay = TimeSpan.FromMilliseconds(50);
            var expectedDelay = TimeSpan.FromMilliseconds(750); // 50 + 100 + 150 + 200 + 250
            var retriableOperation = Using.LinearBackOff(delay).Run(
                () =>
                {
                    times++;
                    if (times > 5)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 150);
            times.Should().Be(6); // 5 failures + 1 success
        }

        [Fact]
        public void Now_delays_by_expected_time_when_execution_fails_five_times_with_overload_2()
        {
            var times = 0;
            var delay = TimeSpan.FromMilliseconds(50);
            var delta = TimeSpan.FromMilliseconds(20);
            var expectedDelay = TimeSpan.FromMilliseconds(540); // 50 + 70 + 90 + 110 + 120
            var retriableOperation = Using.LinearBackOff(delay, delta).Run(
                () =>
                {
                    times++;
                    if (times > 5)
                    {
                        return;
                    }
                    throw new InvalidOperationException();
                });

            var stopWatch = Stopwatch.StartNew();
            retriableOperation.Now();
            stopWatch.Stop();

            stopWatch.Elapsed.Should().BeCloseTo(expectedDelay, precision: 150);
            times.Should().Be(6); // 5 failures + 1 success
        }
    }
}

{'fraction_non_alphanumeric': 0.12638436482084692, 'fraction_numerical': 0.020602605863192184, 'mean_word_length': 1.2704751340358662, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2109956', 'n_tokens_mistral': 3204, 'n_tokens_neox': 2845, 'n_words': 594}