-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathworker_pool_test.rb
More file actions
52 lines (43 loc) · 1.56 KB
/
worker_pool_test.rb
File metadata and controls
52 lines (43 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require File.expand_path('../test_helper', __FILE__)
module Larva
class WorkerPoolTest < Minitest::Test
def test_should_complete_for_no_processors
WorkerPool.start({})
end
def test_process_logs_start_and_end_messages
Propono.config.logger.stubs(:info)
Propono.config.logger.expects(:info).with("Starting 0 threads.")
Propono.config.logger.expects(:info).with("0 threads started.")
WorkerPool.start({})
end
def test_start_worker_logs_exception
Larva::Listener.expects(:listen).raises(RuntimeError)
Propono.config.logger.expects(:error).with do |error|
error.start_with?("Unexpected listener termination:")
end
Propono.config.logger.expects(:error).with('Listener for qux was dead')
Propono.config.logger.expects(:error).with('Some threads have died:')
pool = WorkerPool.new({'qux' => nil})
pool.stubs(:sleep)
err = assert_raises(StandardError) { pool.start }
assert_equal 'Some threads have died', err.message
end
def test_listen_is_called_correctly
Propono.config.logger.stubs(:info)
Propono.config.logger.expects(:info).with("All threads are alive.")
topic_name = "Foo"
processor = mock
Larva::Listener.expects(:listen).with(topic_name, processor)
pool = WorkerPool.new({topic_name => processor})
pool.expects(:sleep).with(60).at_least_once
Thread.any_instance.stubs(alive?: true)
Thread.new do
while true
sleep(1)
pool.stop
end
end
pool.start
end
end
end