class TestThreads

Constants

ROOT

Public Instance Methods

a_thread() click to toggle source
# File test/test_cw_threads.rb, line 22
def a_thread
  @test_var = 2 + 3
end
setup() click to toggle source
# File test/test_cw_threads.rb, line 13
def setup
  @test_var = 0
  @threads = CW::Threads.new(self, [:a_thread])
end
sleep_thread() click to toggle source
# File test/test_cw_threads.rb, line 26
def sleep_thread
  sleep 100
end
teardown() click to toggle source
# File test/test_cw_threads.rb, line 18
def teardown
  @threads = nil
end
test_handles_multiple_threads() click to toggle source

failed on one build

def test_kill_thread_kills_thread
  threads = CW::Threads.new(self, [:sleep_thread])
  threads.start_threads
  thread = threads.threads[0]
  assert_equal "run", thread[:thread].status
  threads.kill_thread thread
  count = 0
  status = ''
  loop do
    status = thread[:thread].status
    break unless status
    sleep 0.01
    count += 1
    break if(count >= 10)
  end

  assert(count < 10)
end
# File test/test_cw_threads.rb, line 70
def test_handles_multiple_threads
  threads = CW::Threads.new(self, [:a_thread, :sleep_thread])
  threads.start_threads
  assert threads.threads[0][:thread].is_a? Thread
  assert threads.threads[1][:thread].is_a? Thread
  assert_nil threads.threads[2]
end
test_start_threads_runs_thread() click to toggle source
# File test/test_cw_threads.rb, line 44
def test_start_threads_runs_thread
  @threads.start_threads
  sleep 0.1
  assert_equal 5, @test_var
end
test_threads_class() click to toggle source
# File test/test_cw_threads.rb, line 30
def test_threads_class
  assert_equal CW::Threads, @threads.class
end
test_threads_exposes_name() click to toggle source
# File test/test_cw_threads.rb, line 34
def test_threads_exposes_name
  @threads.start_threads
  assert_equal :a_thread, (@threads.threads)[0][:name]
end
test_threads_exposes_thread() click to toggle source
# File test/test_cw_threads.rb, line 39
def test_threads_exposes_thread
  @threads.start_threads
  assert @threads.threads[0][:thread].is_a? Thread
end