<commit_before>require File.expand_path(File.join(File.dirname(__FILE__), "..", "helper"))

module Middleware
  class RetryTest < Faraday::TestCase
    def setup
      @times_called = 0
    end

    def conn(*retry_args)
      Faraday.new do |b|
        b.request :retry, *retry_args
        b.adapter :test do |stub|
          stub.post('/unstable') {
            @times_called += 1
            @explode.call @times_called
          }
        end
      end
    end

    def test_unhandled_error
      @explode = lambda {|n| raise "boom!" }
      assert_raise(RuntimeError) { conn.post("/unstable") }
      assert_equal 1, @times_called
    end

    def test_handled_error
      @explode = lambda {|n| raise Errno::ETIMEDOUT }
      assert_raise(Errno::ETIMEDOUT) { conn.post("/unstable") }
      assert_equal 3, @times_called
    end

    def test_legacy_max_retries
      @explode = lambda {|n| raise Errno::ETIMEDOUT }
      assert_raise(Errno::ETIMEDOUT) { conn(1).post("/unstable") }
      assert_equal 2, @times_called
    end

    def test_new_max_retries
      @explode = lambda {|n| raise Errno::ETIMEDOUT }
      assert_raise(Errno::ETIMEDOUT) { conn(:max => 3).post("/unstable") }
      assert_equal 4, @times_called
    end

    def test_interval
      @explode = lambda {|n| raise Errno::ETIMEDOUT }
      started  = Time.now
      assert_raise(Errno::ETIMEDOUT) {
        conn(:max => 2, :interval => 0.1).post("/unstable")
      }
      assert_in_delta 0.2, Time.now - started, 0.02
    end

    def test_custom_exceptions
      @explode = lambda {|n| raise "boom!" }
      assert_raise(RuntimeError) {
        conn(:exceptions => StandardError).post("/unstable")
      }
      assert_equal 3, @times_called
    end
  end
end<commit_msg>tolerate bigger delta in retry middleware test<commit_after>require File.expand_path(File.join(File.dirname(__FILE__), "..", "helper"))

module Middleware
  class RetryTest < Faraday::TestCase
    def setup
      @times_called = 0
    end

    def conn(*retry_args)
      Faraday.new do |b|
        b.request :retry, *retry_args
        b.adapter :test do |stub|
          stub.post('/unstable') {
            @times_called += 1
            @explode.call @times_called
          }
        end
      end
    end

    def test_unhandled_error
      @explode = lambda {|n| raise "boom!" }
      assert_raise(RuntimeError) { conn.post("/unstable") }
      assert_equal 1, @times_called
    end

    def test_handled_error
      @explode = lambda {|n| raise Errno::ETIMEDOUT }
      assert_raise(Errno::ETIMEDOUT) { conn.post("/unstable") }
      assert_equal 3, @times_called
    end

    def test_legacy_max_retries
      @explode = lambda {|n| raise Errno::ETIMEDOUT }
      assert_raise(Errno::ETIMEDOUT) { conn(1).post("/unstable") }
      assert_equal 2, @times_called
    end

    def test_new_max_retries
      @explode = lambda {|n| raise Errno::ETIMEDOUT }
      assert_raise(Errno::ETIMEDOUT) { conn(:max => 3).post("/unstable") }
      assert_equal 4, @times_called
    end

    def test_interval
      @explode = lambda {|n| raise Errno::ETIMEDOUT }
      started  = Time.now
      assert_raise(Errno::ETIMEDOUT) {
        conn(:max => 2, :interval => 0.1).post("/unstable")
      }
      assert_in_delta 0.2, Time.now - started, 0.03
    end

    def test_custom_exceptions
      @explode = lambda {|n| raise "boom!" }
      assert_raise(RuntimeError) {
        conn(:exceptions => StandardError).post("/unstable")
      }
      assert_equal 3, @times_called
    end
  end
end
{'fraction_non_alphanumeric': 0.11931014984450099, 'fraction_numerical': 0.009612666101215719, 'mean_word_length': 2.577350859453994, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5370234', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1158, 'n_words': 249}