electric_slide 0.0.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ElectricSlide::RoundRobin do
4
- def dummy_queued_call
5
- dqc = ElectricSlide::QueuedCall.new dummy_call
6
- flexmock(dqc).should_receive(:hold).once
7
- flexmock(dqc).should_receive(:make_ready!).once
8
- dqc
9
- end
10
-
11
- before :each do
12
- @queue = ElectricSlide::RoundRobin.new
13
- end
14
-
15
- describe "Queue is empty at start" do
16
- subject { ElectricSlide::RoundRobin.new }
17
- its(:queue) { should have(0).items }
18
- end
19
-
20
- it 'should properly enqueue a call' do
21
- call = ElectricSlide::QueuedCall.new dummy_call
22
- flexmock(call).should_receive(:hold).once
23
- @queue.enqueue call
24
- @queue.instance_variable_get(:@queue).first.should be call
25
- end
26
-
27
- it 'should return the call object that is passed in' do
28
- call = dummy_queued_call
29
- @queue.enqueue call
30
- @queue.next_call.should be call
31
- end
32
-
33
- it 'should block an agent requesting a call until a call becomes available' do
34
- call = dummy_queued_call
35
- agent_thread = Thread.new { @queue.next_call }
36
-
37
- # Give the agent thread a chance to block...
38
- sleep 0.5
39
-
40
- @queue.agents_waiting.count.should == 1
41
-
42
- @queue.enqueue call
43
-
44
- # Give the agent thread a chance to retrieve the call...
45
- sleep 0.5
46
- @queue.agents_waiting.count.should == 0
47
- agent_thread.kill
48
- end
49
-
50
- it 'should unblock only one agent per call entering the queue' do
51
- call = dummy_queued_call
52
- agent1_thread = Thread.new { @queue.next_call }
53
- agent2_thread = Thread.new { @queue.next_call }
54
-
55
- # Give the agent threads a chance to block...
56
- sleep 0.5
57
-
58
- @queue.agents_waiting.count.should == 2
59
-
60
- @queue.enqueue call
61
-
62
- # Give the agent thread a chance to retrieve the call...
63
- sleep 0.5
64
- @queue.agents_waiting.count.should == 1
65
- agent1_thread.kill
66
- agent2_thread.kill
67
- end
68
-
69
- it 'should properly enqueue calls and return them in the same order' do
70
- call1 = dummy_queued_call
71
- call2 = dummy_queued_call
72
- call3 = dummy_queued_call
73
- threads = {}
74
-
75
- threads[:call1] = Thread.new { @queue.enqueue call1 }
76
- sleep 0.5
77
- threads[:call2] = Thread.new { @queue.enqueue call2 }
78
- sleep 0.5
79
- threads[:call3] = Thread.new { @queue.enqueue call3 }
80
- sleep 0.5
81
-
82
-
83
- @queue.next_call.should be call1
84
- @queue.next_call.should be call2
85
- @queue.next_call.should be call3
86
- end
87
- end