Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 92 lines (79 sloc) 2.311 kB
7f5a1a0 @floere + scheduler
authored
1 # encoding: utf-8
2 require 'spec_helper'
3
4 describe Picky::Scheduler do
5
6 context 'default params' do
7 let(:scheduler) { described_class.new }
8
9 context 'without forking' do
10 before(:each) do
7a91512 @floere + Replace mock with stub.
authored
11 scheduler.stub :fork? => false
7f5a1a0 @floere + scheduler
authored
12 end
13 context 'non-stubbed forking' do
14 it 'works correctly' do
15 scheduler.schedule { sleep 0.01 }
16 scheduler.schedule { sleep 0.01 }
17 scheduler.schedule { sleep 0.01 }
18 scheduler.schedule { sleep 0.01 }
19 end
20 it 'works correctly' do
21 called = 0
22
23 scheduler.schedule { called += 1 }
24 scheduler.schedule { called += 1 }
25 scheduler.schedule { called += 1 }
26 scheduler.schedule { called += 1 }
27
28 called.should == 4
29 end
30 end
31 end
32
33 describe 'fork?' do
34 context 'OS can fork' do
35 it 'returns false' do
239d898 @floere + Move to RSpec 3 finished.
authored
36 scheduler.fork?.should be_falsy
7f5a1a0 @floere + scheduler
authored
37 end
38 end
39 context 'OS cannot fork' do
40 before(:each) do
7a91512 @floere + Replace mock with stub.
authored
41 Process.stub :fork => nil
7f5a1a0 @floere + scheduler
authored
42 end
43 it 'returns false' do
239d898 @floere + Move to RSpec 3 finished.
authored
44 scheduler.fork?.should be_falsy
7f5a1a0 @floere + scheduler
authored
45 end
46 end
47 end
48 end
49 context 'default params' do
50 let(:scheduler) { described_class.new parallel: true }
51
79a9c0c @floere + history, + 4.0.0-pre1, + parallel indexing
authored
52 context 'stubbed forking' do
53 it 'works correctly' do
54 scheduler.scheduler.should_receive(:schedule).exactly(4).times.and_yield
55
56 scheduler.schedule { sleep 0.01 }
57 scheduler.schedule { sleep 0.01 }
58 scheduler.schedule { sleep 0.01 }
59 scheduler.schedule { sleep 0.01 }
60 end
61 it 'works correctly' do
c5c9770 @floere + Replace stub with double. Replace any_number_of_times with at_least…
authored
62 scheduler.scheduler.should_receive(:schedule).at_least(1).and_yield
79a9c0c @floere + history, + 4.0.0-pre1, + parallel indexing
authored
63
64 called = 0
65
66 scheduler.schedule { called += 1 }
67 scheduler.schedule { called += 1 }
68 scheduler.schedule { called += 1 }
69 scheduler.schedule { called += 1 }
70
71 called.should == 4
72 end
73 end
74
7f5a1a0 @floere + scheduler
authored
75 describe 'fork?' do
76 context 'OS can fork' do
77 it 'returns true' do
78 scheduler.fork?.should == true
79 end
80 end
79a9c0c @floere + history, + 4.0.0-pre1, + parallel indexing
authored
81 # context 'OS cannot fork' do
82 # before(:each) do
83 # Process.send :undef, :fork
84 # end
85 # it 'returns false' do
86 # scheduler.fork?.should == false
87 # end
88 # end
7f5a1a0 @floere + scheduler
authored
89 end
90 end
91
92 end
Something went wrong with that request. Please try again.