Sha256: 67139f2256cad4461732ecd67bc6e2e8696464c5fae1232a15f286c2cf042d01
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
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: 20) buffer = [] f = spin do loop { t.process { buffer << 1 } } end sleep 0.25 f.stop puts "count: #{buffer.size}" 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polyphony-0.29 | test/test_throttler.rb |