VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/lib/gems/2.5.0/gems/eventmachine-1.2.7/tests/test_tick_loop.rb
require "test/unit"
require 'em_test_helper'

class TestEmTickLoop < Test::Unit::TestCase
  def test_em_tick_loop
    i = 0
    EM.tick_loop { i += 1; EM.stop if i == 10 }
    EM.run { EM.add_timer(1) { EM.stop } }
    assert_equal i, 10
  end
  
  def test_tick_loop_on_stop
    t = nil
    tick_loop = EM.tick_loop { :stop }
    tick_loop.on_stop { t = true }
    EM.run { EM.next_tick { EM.stop } }
    assert t
  end
  
  def test_start_twice
    i = 0
    s = 0
    tick_loop = EM.tick_loop { i += 1; :stop }
    tick_loop.on_stop { s += 1; EM.stop }
    EM.run { EM.next_tick { EM.stop } }
    assert_equal 1, i
    assert_equal 1, s
    tick_loop.start
    EM.run { EM.next_tick { EM.stop } }
    assert_equal 2, i
    assert_equal 1, s # stop callbacks are only called once
  end
  
  def test_stop
    i, s = 0, 0
    tick_loop = EM.tick_loop { i += 1 }
    tick_loop.on_stop { s += 1 }
    EM.run { EM.next_tick { tick_loop.stop; EM.next_tick { EM.stop } } }
    assert tick_loop.stopped?
    assert_equal 1, i
    assert_equal 1, s
  end
  
  def test_immediate_stops
    s = 0
    tick_loop = EM::TickLoop.new { }
    tick_loop.on_stop { s += 1 }
    tick_loop.on_stop { s += 1 }
    assert_equal 2, s
  end
  
  def test_stopped
    tick_loop = EM::TickLoop.new { }
    assert tick_loop.stopped?
    tick_loop.start
    assert !tick_loop.stopped?
  end
    
end

VaKeR 2022