Sha256: 9accf9c6f2bdb921a672a94e894c94cad9ddf49887d359dafad27e77fe0093f8

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 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
    assert buffer.size >= 2
    assert buffer.size <= 3
  ensure
    t.stop
  end

  def test_throttler_with_hash_of_rate
    t = Polyphony::Throttler.new(rate: 100)
    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_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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polyphony-0.27 test/test_throttler.rb