Sha256: 6a0a61598882cc9344c188b1a913ce0a950654f55e29d153c9df8a250ad6dec4

Contents?: true

Size: 1011 Bytes

Versions: 7

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

require_relative 'helper'

class ThrottlerTest < MiniTest::Test
  def test_throttler_with_rate
    t = Polyphony::Throttler.new(100)
    buffer = []
    f = spin { loop { t.process { buffer << 1 } } }
    sleep 0.02
    f.stop
    snooze
    assert buffer.size >= 2
    assert buffer.size <= 3
  ensure
    t.stop
  end

  def test_throttler_with_hash_of_rate
    t = Polyphony::Throttler.new(rate: 20)
    buffer = []
    f = spin do
      loop { t.process { buffer << 1 } }
    end
    sleep 0.25
    f.stop
    assert (2..6).include?(buffer.size)
  ensure
    t.stop
  end

  def test_throttler_with_hash_of_interval
    t = Polyphony::Throttler.new(interval: 0.01)
    buffer = []
    f = spin { loop { t.process { buffer << 1 } } }
    sleep 0.02
    f.stop
    assert buffer.size >= 2
    assert buffer.size <= 3
  ensure
    t.stop
  end

  def test_throttler_with_invalid_argument
    assert_raises RuntimeError do
      Polyphony::Throttler.new(:foobar)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
polyphony-0.43.2 test/test_throttler.rb
polyphony-0.43.1 test/test_throttler.rb
polyphony-0.43 test/test_throttler.rb
polyphony-0.42 test/test_throttler.rb
polyphony-0.41 test/test_throttler.rb
polyphony-0.40 test/test_throttler.rb
polyphony-0.38 test/test_throttler.rb