-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathmultiprocess_queue_client_test.rb
More file actions
72 lines (56 loc) · 1.92 KB
/
multiprocess_queue_client_test.rb
File metadata and controls
72 lines (56 loc) · 1.92 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'test_helper'
class TestClientRetriever
def initialize(conf, queue, options)
end
end
class TestProcessClient < MultiprocessQueueClient
attr_reader :exit
def clazz
TestClientRetriever
end
end
describe 'MultiprocessQueueClient' do
let(:client) { TestProcessClient.new }
describe 'go' do
it 'must call run on the retriever with correct config' do
token = Faker::Internet.password
process_count = 3
mapping_file = <<-DOC.gsub(/^\s+/, '')
# TOKEN NUM_PROCS LIMIT
#{Faker::Internet.password} #{process_count} 24
DOC
settings = { 'mirror' => { 'token' => token, 'req_limit' => 10 } }
client.stubs(:settings).returns(settings)
client.stubs(:options).returns({ inproc: true })
File.stubs(:open).returns(stub(readlines: mapping_file.split(/\n/)))
TestClientRetriever.any_instance.stubs(:stop)
Process.stubs(:waitpid)
TestClientRetriever.any_instance.expects(:run).at_least(process_count)
client.go
end
it 'must fork a subprocess when inproc is false' do
mapping_file = <<-DOC.gsub(/^\s+/, '')
# TOKEN NUM_PROCS LIMIT
#{Faker::Internet.password} 2 24
DOC
settings = { 'mirror' => { 'token' => Faker::Internet.password, 'req_limit' => 10 } }
client.stubs(:settings).returns(settings)
client.stubs(:options).returns({ inproc: false })
File.stubs(:open).returns(stub(readlines: mapping_file.split(/\n/)))
TestClientRetriever.any_instance.stubs(:stop)
TestClientRetriever.stubs(:run)
pid = Faker::Number.number(2)
Process.expects(:fork).returns(pid).twice
Process.expects(:waitpid).with(pid, 0).twice
client.go
end
end
describe 'validate' do
it 'must call trolltop.die' do
GHTorrent::Command.any_instance.expects(:validate)
Optimist.expects(:die)
client.stubs(:args).returns([])
client.validate
end
end
end