Sha256: 49344ad2ea9bbc3c5d377a0d7b987556b254d61140496af411b9bcc474321392
Contents?: true
Size: 1.02 KB
Versions: 6
Compression:
Stored size: 1.02 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 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 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
6 entries across 6 versions & 1 rubygems