![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/lib/gems/2.5.0/gems/eventmachine-1.2.7/tests/ |
Upload File : |
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