Class: TestCWStream

Inherits:
MiniTest::Test
  • Object
show all
Defined in:
/Users/martyn/cw/cw_clone/test/test_cw_threads.rb

Constant Summary

ROOT =
File.expand_path File.dirname(__FILE__) + '/../../'

Instance Method Summary (collapse)

Instance Method Details

- (Object) a_thread



13
14
15
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 13

def a_thread
  @test_var = 2 + 3
end

- (Object) setup



21
22
23
24
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 21

def setup
  @test_var = 0
  @threads = CWG::CWThreads.new(self, [:a_thread])
end

- (Object) sleep_thread



17
18
19
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 17

def sleep_thread
  sleep 100
end

- (Object) teardown



26
27
28
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 26

def teardown
  @cw = nil
end

- (Object) test_cw_threads



30
31
32
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 30

def test_cw_threads
  assert true
end

- (Object) test_handles_multiple_threads



69
70
71
72
73
74
75
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 69

def test_handles_multiple_threads
  threads = CWG::CWThreads.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

- (Object) test_kill_thread_kills_thread



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 50

def test_kill_thread_kills_thread
  threads = CWG::CWThreads.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

- (Object) test_start_threads_runs_thread



44
45
46
47
48
# File '/Users/martyn/cw/cw_clone/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

- (Object) test_thread_false_or_nil_returns_true_and_false



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 77

def test_thread_false_or_nil_returns_true_and_false
  @threads.start_threads
  thread = @threads.threads[0]
  refute @threads.thread_false_or_nil?(@threads.threads[0])
  @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
  assert @threads.thread_false_or_nil?(@threads.threads[0])
end

- (Object) test_threads_exposes_name



34
35
36
37
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 34

def test_threads_exposes_name
  @threads.start_threads
  assert_equal :a_thread, (@threads.threads)[0][:name]
end

- (Object) test_threads_exposes_thread



39
40
41
42
# File '/Users/martyn/cw/cw_clone/test/test_cw_threads.rb', line 39

def test_threads_exposes_thread
  @threads.start_threads
  assert @threads.threads[0][:thread].is_a? Thread
end