This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 351
/
task_manager_spec.rb
74 lines (68 loc) · 1.97 KB
/
task_manager_spec.rb
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require File.join(File.dirname(__FILE__), 'spec_helper')
describe VCAP::Stager::TaskManager do
describe '#start_tasks'do
it 'should start as many tasks as allowed' do
tm = VCAP::Stager::TaskManager.new(3)
tasks = []
for ii in 0..2
t = make_mock_task(ii)
t.should_receive(:perform).with(any_args())
tasks << t
end
t = make_mock_task(3)
t.should_not_receive(:perform)
tasks << t
# XXX :(
tm.instance_variable_set(:@queued_tasks, tasks)
tm.send(:start_tasks)
end
it 'should update varz' do
tm = VCAP::Stager::TaskManager.new(2)
tasks = []
for ii in 0..1
t = make_mock_task(ii)
t.should_receive(:perform).with(any_args())
tasks << t
end
for ii in 2..3
tasks << make_mock_task(ii)
end
# XXX :(
tm.instance_variable_set(:@queued_tasks, tasks)
varz = {}
tm.varz = varz
tm.send(:start_tasks)
varz[:num_pending_tasks].should == 2
varz[:num_active_tasks].should == 2
end
it 'should checkout a secure user per task' do
um = mock(:secure_user_manager)
um.should_receive(:checkout_user).twice()
tm = VCAP::Stager::TaskManager.new(3, um)
tasks = []
for ii in 0..1
t = make_mock_task(ii)
t.should_receive(:perform).with(any_args())
t.should_receive(:user=).with(nil)
tasks << t
end
tm.instance_variable_set(:@queued_tasks, tasks)
tm.send(:start_tasks)
end
end
describe '#task_completed' do
it 'should emit a task_completed event' do
tm = VCAP::Stager::TaskManager.new(3)
task = make_mock_task(1)
task.stub(:user).and_return(nil)
tm.should_receive(:event).with(:task_completed, task, {})
tm.should_receive(:event).with(:idle)
tm.send(:task_completed, task, {})
end
end
def make_mock_task(id)
t = mock("task_#{id}")
t.stub(:task_id).and_return(id)
t
end
end