|
10 | 10 |
|
11 | 11 | it_should_behave_like :thread_pool
|
12 | 12 |
|
13 |
| - context '#max_queue' do |
| 13 | + context '#initialize' do |
| 14 | + |
| 15 | + it 'defaults :min_length to DEFAULT_MIN_POOL_SIZE' do |
| 16 | + subject = described_class.new |
| 17 | + subject.min_length.should eq described_class::DEFAULT_MIN_POOL_SIZE |
| 18 | + end |
| 19 | + |
| 20 | + it 'defaults :max_length to DEFAULT_MAX_POOL_SIZE' do |
| 21 | + subject = described_class.new |
| 22 | + subject.max_length.should eq described_class::DEFAULT_MAX_POOL_SIZE |
| 23 | + end |
| 24 | + |
| 25 | + it 'defaults :idletime to DEFAULT_THREAD_IDLETIMEOUT' do |
| 26 | + subject = described_class.new |
| 27 | + subject.idletime.should eq described_class::DEFAULT_THREAD_IDLETIMEOUT |
| 28 | + end |
14 | 29 |
|
15 |
| - it 'is set to zero by default' do |
16 |
| - pending |
| 30 | + it 'defaults :max_queue to DEFAULT_MAX_QUEUE_SIZE' do |
| 31 | + subject = described_class.new |
| 32 | + subject.max_queue.should eq described_class::DEFAULT_MAX_QUEUE_SIZE |
17 | 33 | end
|
18 | 34 |
|
| 35 | + it 'defaults :overflow_policy to :abort' do |
| 36 | + subject = described_class.new |
| 37 | + subject.overflow_policy.should eq :abort |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + context '#max_queue' do |
| 42 | + |
| 43 | + let!(:expected_max){ 100 } |
| 44 | + subject{ described_class.new(max_queue: expected_max) } |
| 45 | + |
19 | 46 | it 'returns the set value on creation' do
|
20 |
| - pending |
| 47 | + subject.max_queue.should eq expected_max |
21 | 48 | end
|
22 | 49 |
|
23 | 50 | it 'returns the set value when running' do
|
24 |
| - pending |
| 51 | + 5.times{ subject.post{ sleep(0.1) } } |
| 52 | + sleep(0.1) |
| 53 | + subject.max_queue.should eq expected_max |
25 | 54 | end
|
26 | 55 |
|
27 | 56 | it 'returns the set value after stopping' do
|
28 |
| - pending |
| 57 | + 5.times{ subject.post{ sleep(0.1) } } |
| 58 | + sleep(0.1) |
| 59 | + subject.shutdown |
| 60 | + subject.wait_for_termination(1) |
| 61 | + subject.max_queue.should eq expected_max |
29 | 62 | end
|
30 | 63 | end
|
31 | 64 |
|
32 | 65 | context '#queue_length' do
|
33 | 66 |
|
34 | 67 | it 'returns zero on creation' do
|
35 |
| - pending |
| 68 | + subject.queue_length.should eq 0 |
36 | 69 | end
|
37 | 70 |
|
38 | 71 | it 'returns zero when there are no enqueued tasks' do
|
39 |
| - pending |
| 72 | + 5.times{ subject.post{ nil } } |
| 73 | + sleep(0.1) |
| 74 | + subject.queue_length.should eq 0 |
40 | 75 | end
|
41 | 76 |
|
42 | 77 | it 'returns the size of the queue when tasks are enqueued' do
|
43 |
| - pending |
| 78 | + 100.times{ subject.post{ sleep(0.5) } } |
| 79 | + sleep(0.1) |
| 80 | + subject.queue_length.should > 0 |
44 | 81 | end
|
45 | 82 |
|
46 | 83 | it 'returns zero when stopped' do
|
47 |
| - pending |
| 84 | + 100.times{ subject.post{ sleep(0.5) } } |
| 85 | + sleep(0.1) |
| 86 | + subject.shutdown |
| 87 | + subject.wait_for_termination(1) |
| 88 | + subject.queue_length.should eq 0 |
48 | 89 | end
|
49 | 90 | end
|
50 | 91 |
|
51 | 92 | context '#remaining_capacity' do
|
52 | 93 |
|
| 94 | + let!(:expected_max){ 100 } |
| 95 | + subject{ described_class.new(max_queue: expected_max) } |
| 96 | + |
53 | 97 | it 'returns -1 when :max_queue is set to zero' do
|
54 |
| - pending |
| 98 | + executor = described_class.new(max_queue: 0) |
| 99 | + executor.remaining_capacity.should eq -1 |
55 | 100 | end
|
56 | 101 |
|
57 |
| - it 'returns :max_size on creation' do |
58 |
| - pending |
| 102 | + it 'returns :max_length on creation' do |
| 103 | + subject.remaining_capacity.should eq expected_max |
59 | 104 | end
|
60 | 105 |
|
61 |
| - it 'returns :max_size when no tasks are enqueued' do |
62 |
| - pending |
| 106 | + it 'returns :max_length when no tasks are enqueued' do |
| 107 | + 5.times{ subject.post{ nil } } |
| 108 | + sleep(0.1) |
| 109 | + subject.remaining_capacity.should eq eq expected_max |
63 | 110 | end
|
64 | 111 |
|
65 | 112 | it 'returns the remaining capacity when tasks are enqueued' do
|
66 |
| - pending |
| 113 | + 100.times{ subject.post{ sleep(0.5) } } |
| 114 | + subject.remaining_capacity.should < expected_max |
67 | 115 | end
|
68 | 116 |
|
69 |
| - it 'returns :max_size when stopped' do |
70 |
| - pending |
| 117 | + it 'returns :max_length when stopped' do |
| 118 | + 100.times{ subject.post{ sleep(0.5) } } |
| 119 | + subject.shutdown |
| 120 | + subject.wait_for_termination(1) |
| 121 | + subject.remaining_capacity.should eq expected_max |
71 | 122 | end
|
72 | 123 | end
|
73 | 124 |
|
|
0 commit comments