From 5571dc766e2143e39762ff0b47c41d1c2e154f4c Mon Sep 17 00:00:00 2001 From: Benjamin Sanders Date: Sat, 11 Oct 2025 10:34:24 -0400 Subject: Vendor bundled gems for deployment --- .../gems/eventmachine-1.2.7/tests/test_timers.rb | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/tests/test_timers.rb (limited to 'vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/tests/test_timers.rb') diff --git a/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/tests/test_timers.rb b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/tests/test_timers.rb new file mode 100644 index 0000000..88b3b78 --- /dev/null +++ b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/tests/test_timers.rb @@ -0,0 +1,130 @@ +require 'em_test_helper' + +class TestTimers < Test::Unit::TestCase + + def test_timer_with_block + x = false + EM.run { + EM::Timer.new(0) { + x = true + EM.stop + } + } + assert x + end + + def test_timer_with_proc + x = false + EM.run { + EM::Timer.new(0, proc { + x = true + EM.stop + }) + } + assert x + end + + def test_timer_cancel + assert_nothing_raised do + EM.run { + timer = EM::Timer.new(0.01) { flunk "Timer was not cancelled." } + timer.cancel + + EM.add_timer(0.02) { EM.stop } + } + end + end + + def test_periodic_timer + x = 0 + EM.run { + EM::PeriodicTimer.new(0.01) do + x += 1 + EM.stop if x == 4 + end + } + + assert_equal 4, x + end + + def test_add_periodic_timer + x = 0 + EM.run { + t = EM.add_periodic_timer(0.01) do + x += 1 + EM.stop if x == 4 + end + assert t.respond_to?(:cancel) + } + assert_equal 4, x + end + + def test_periodic_timer_cancel + x = 0 + EM.run { + pt = EM::PeriodicTimer.new(0.01) { x += 1 } + pt.cancel + EM::Timer.new(0.02) { EM.stop } + } + assert_equal 0, x + end + + def test_add_periodic_timer_cancel + x = 0 + EM.run { + pt = EM.add_periodic_timer(0.01) { x += 1 } + EM.cancel_timer(pt) + EM.add_timer(0.02) { EM.stop } + } + assert_equal 0, x + end + + def test_periodic_timer_self_cancel + x = 0 + EM.run { + pt = EM::PeriodicTimer.new(0) { + x += 1 + if x == 4 + pt.cancel + EM.stop + end + } + } + assert_equal 4, x + end + + def test_oneshot_timer_large_future_value + large_value = 11948602000 + EM.run { + EM.add_timer(large_value) { EM.stop } + EM.add_timer(0.02) { EM.stop } + } + end + + # This test is only applicable to compiled versions of the reactor. + # Pure ruby and java versions have no built-in limit on the number of outstanding timers. + unless [:pure_ruby, :java].include? EM.library_type + def test_timer_change_max_outstanding + defaults = EM.get_max_timers + EM.set_max_timers(100) + + one_hundred_one_timers = lambda do + 101.times { EM.add_timer(0.01) {} } + EM.stop + end + + assert_raises(RuntimeError) do + EM.run( &one_hundred_one_timers ) + end + + EM.set_max_timers( 101 ) + + assert_nothing_raised do + EM.run( &one_hundred_one_timers ) + end + ensure + EM.set_max_timers(defaults) + end + end + +end -- cgit v1.2.3