mcollective-client 2.2.4 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mcollective-client might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/lib/mcollective/application.rb +25 -34
- data/lib/mcollective/client.rb +91 -33
- data/lib/mcollective/config.rb +42 -43
- data/lib/mcollective/data/base.rb +1 -1
- data/lib/mcollective/data/result.rb +6 -2
- data/lib/mcollective/ddl/agentddl.rb +28 -1
- data/lib/mcollective/ddl/base.rb +8 -6
- data/lib/mcollective/log.rb +11 -3
- data/lib/mcollective/logger/file_logger.rb +4 -4
- data/lib/mcollective/matcher.rb +9 -1
- data/lib/mcollective/message.rb +14 -23
- data/lib/mcollective/optionparser.rb +9 -1
- data/lib/mcollective/pluginpackager.rb +24 -3
- data/lib/mcollective/pluginpackager/agent_definition.rb +12 -12
- data/lib/mcollective/pluginpackager/standard_definition.rb +12 -12
- data/lib/mcollective/rpc/agent.rb +15 -12
- data/lib/mcollective/rpc/client.rb +67 -31
- data/lib/mcollective/rpc/helpers.rb +7 -1
- data/lib/mcollective/rpc/reply.rb +3 -1
- data/lib/mcollective/shell.rb +45 -8
- data/lib/mcollective/util.rb +37 -1
- data/lib/mcollective/windows_daemon.rb +14 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/application_spec.rb +45 -26
- data/spec/unit/cache_spec.rb +3 -3
- data/spec/unit/client_spec.rb +269 -24
- data/spec/unit/config_spec.rb +89 -26
- data/spec/unit/data/base_spec.rb +1 -0
- data/spec/unit/data/result_spec.rb +19 -1
- data/spec/unit/data_spec.rb +3 -0
- data/spec/unit/ddl/agentddl_spec.rb +32 -0
- data/spec/unit/ddl/base_spec.rb +4 -0
- data/spec/unit/ddl/dataddl_spec.rb +1 -1
- data/spec/unit/log_spec.rb +44 -27
- data/spec/unit/logger/base_spec.rb +1 -1
- data/spec/unit/matcher_spec.rb +14 -0
- data/spec/unit/message_spec.rb +24 -0
- data/spec/unit/optionparser_spec.rb +99 -0
- data/spec/unit/pluginpackager/agent_definition_spec.rb +48 -17
- data/spec/unit/pluginpackager/standard_definition_spec.rb +44 -20
- data/spec/unit/pluginpackager_spec.rb +31 -7
- data/spec/unit/plugins/mcollective/agent/rpcutil_spec.rb +176 -0
- data/spec/unit/plugins/mcollective/application/plugin_spec.rb +81 -0
- data/spec/unit/plugins/mcollective/audit/logfile_spec.rb +44 -0
- data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +118 -27
- data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +168 -34
- data/spec/unit/plugins/mcollective/data/agent_data_spec.rb +1 -0
- data/spec/unit/plugins/mcollective/data/fstat_data_spec.rb +1 -0
- data/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb +10 -0
- data/spec/unit/plugins/mcollective/discovery/stdin_spec.rb +65 -0
- data/spec/unit/plugins/mcollective/facts/yaml_facts_spec.rb +65 -0
- data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +240 -219
- data/spec/unit/plugins/mcollective/packagers/modulepackage_packager_spec.rb +209 -0
- data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +223 -109
- data/spec/unit/rpc/actionrunner_spec.rb +2 -1
- data/spec/unit/rpc/agent_spec.rb +130 -1
- data/spec/unit/rpc/client_spec.rb +169 -3
- data/spec/unit/security/base_spec.rb +0 -1
- data/spec/unit/shell_spec.rb +76 -3
- data/spec/unit/util_spec.rb +69 -1
- data/spec/unit/windows_daemon_spec.rb +30 -9
- metadata +104 -90
- data/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb +0 -34
- data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +0 -424
- data/spec/unit/plugins/mcollective/validator/any_validator_spec.rb +0 -15
@@ -11,15 +11,26 @@ module MCollective
|
|
11
11
|
|
12
12
|
def service_main
|
13
13
|
Log.debug("Starting Windows Service Daemon")
|
14
|
+
while running?
|
15
|
+
return if state != RUNNING
|
16
|
+
@runner = Runner.new(nil)
|
17
|
+
@runner.run
|
18
|
+
end
|
14
19
|
|
15
|
-
|
16
|
-
|
20
|
+
# Right now we don't have a way to let the connection and windows sleeper threads
|
21
|
+
# run to conclusion. Until that is possible we iterate the list of living threads
|
22
|
+
# and kill everything that isn't the main thread. This lets us exit cleanly.
|
23
|
+
Thread.list.each do |t|
|
24
|
+
if t != Thread.current
|
25
|
+
t.kill
|
26
|
+
end
|
27
|
+
end
|
17
28
|
end
|
18
29
|
|
19
30
|
def service_stop
|
20
31
|
Log.info("Windows service stopping")
|
32
|
+
@runner.stop
|
21
33
|
PluginManager["connector_plugin"].disconnect
|
22
|
-
exit! 0
|
23
34
|
end
|
24
35
|
end
|
25
36
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,11 +15,13 @@ require 'ostruct'
|
|
15
15
|
require 'tmpdir'
|
16
16
|
require 'tempfile'
|
17
17
|
require 'fileutils'
|
18
|
+
require 'mcollective/test'
|
18
19
|
|
19
20
|
require 'monkey_patches/instance_variable_defined'
|
20
21
|
|
21
22
|
RSpec.configure do |config|
|
22
23
|
config.mock_with :mocha
|
24
|
+
config.include(MCollective::Test::Matchers)
|
23
25
|
|
24
26
|
config.before :each do
|
25
27
|
MCollective::Config.instance.set_config_defaults("")
|
@@ -174,6 +174,25 @@ module MCollective
|
|
174
174
|
@argv_backup.each{|a| ARGV << a}
|
175
175
|
end
|
176
176
|
|
177
|
+
it "should support unsetting boolean options" do
|
178
|
+
Application.any_instance.stubs("main").returns(true)
|
179
|
+
|
180
|
+
Application.option :foo,
|
181
|
+
:description => "meh",
|
182
|
+
:arguments => "--[no-]foo",
|
183
|
+
:type => :boolean
|
184
|
+
|
185
|
+
ARGV.clear
|
186
|
+
ARGV << "--no-foo"
|
187
|
+
|
188
|
+
a = Application.new
|
189
|
+
a.run
|
190
|
+
a.configuration.should == {:foo=>false}
|
191
|
+
|
192
|
+
ARGV.clear
|
193
|
+
@argv_backup.each{|a| ARGV << a}
|
194
|
+
end
|
195
|
+
|
177
196
|
it "should set the application description as head" do
|
178
197
|
OptionParser.any_instance.stubs(:define_head).with("meh")
|
179
198
|
|
@@ -395,7 +414,7 @@ module MCollective
|
|
395
414
|
|
396
415
|
describe "#halt" do
|
397
416
|
before do
|
398
|
-
@stats = {:discoverytime => 0, :discovered => 0, :failcount => 0, :responses => 0}
|
417
|
+
@stats = {:discoverytime => 0, :discovered => 0, :failcount => 0, :responses => 0, :okcount => 0}
|
399
418
|
end
|
400
419
|
|
401
420
|
it "should exit with code 0 if discovery was done and all responses passed" do
|
@@ -404,28 +423,25 @@ module MCollective
|
|
404
423
|
@stats[:discoverytime] = 2
|
405
424
|
@stats[:discovered] = 2
|
406
425
|
@stats[:responses] = 2
|
426
|
+
@stats[:okcount] = 2
|
407
427
|
|
408
|
-
app.
|
409
|
-
|
410
|
-
app.halt(@stats)
|
428
|
+
app.halt_code(@stats).should == 0
|
411
429
|
end
|
412
430
|
|
413
431
|
it "should exit with code 0 if no discovery were done but responses were received" do
|
414
432
|
app = Application.new
|
415
433
|
|
416
434
|
@stats[:responses] = 1
|
435
|
+
@stats[:okcount] = 1
|
436
|
+
@stats[:discovered] = 1
|
417
437
|
|
418
|
-
app.
|
419
|
-
|
420
|
-
app.halt(@stats)
|
438
|
+
app.halt_code(@stats).should == 0
|
421
439
|
end
|
422
440
|
|
423
|
-
it "should exit with code
|
441
|
+
it "should exit with code 1 if discovery info is missing" do
|
424
442
|
app = Application.new
|
425
443
|
|
426
|
-
app.
|
427
|
-
|
428
|
-
app.halt({})
|
444
|
+
app.halt_code({}).should == 1
|
429
445
|
end
|
430
446
|
|
431
447
|
it "should exit with code 1 if no nodes were discovered and discovery was done" do
|
@@ -433,22 +449,29 @@ module MCollective
|
|
433
449
|
|
434
450
|
@stats[:discoverytime] = 2
|
435
451
|
|
436
|
-
app.
|
437
|
-
|
438
|
-
app.halt(@stats)
|
452
|
+
app.halt_code(@stats).should == 1
|
439
453
|
end
|
440
454
|
|
441
455
|
it "should exit with code 2 if a request failed for some nodes" do
|
442
456
|
app = Application.new
|
443
457
|
|
444
|
-
@stats[:discovered] =
|
458
|
+
@stats[:discovered] = 2
|
445
459
|
@stats[:failcount] = 1
|
446
460
|
@stats[:discoverytime] = 2
|
447
|
-
@stats[:responses] =
|
461
|
+
@stats[:responses] = 2
|
462
|
+
|
463
|
+
app.halt_code(@stats).should == 2
|
464
|
+
end
|
465
|
+
|
466
|
+
it "should exit with code 2 when no discovery were done and there were failure results" do
|
467
|
+
app = Application.new
|
448
468
|
|
449
|
-
|
469
|
+
@stats[:discovered] = 1
|
470
|
+
@stats[:failcount] = 1
|
471
|
+
@stats[:discoverytime] = 0
|
472
|
+
@stats[:responses] = 1
|
450
473
|
|
451
|
-
app.
|
474
|
+
app.halt_code(@stats).should == 2
|
452
475
|
end
|
453
476
|
|
454
477
|
it "should exit with code 3 if no responses were received after discovery" do
|
@@ -457,17 +480,13 @@ module MCollective
|
|
457
480
|
@stats[:discovered] = 1
|
458
481
|
@stats[:discoverytime] = 2
|
459
482
|
|
460
|
-
app.
|
461
|
-
|
462
|
-
app.halt(@stats)
|
483
|
+
app.halt_code(@stats).should == 3
|
463
484
|
end
|
464
485
|
|
465
486
|
it "should exit with code 4 if no discovery was done and no responses were received" do
|
466
487
|
app = Application.new
|
467
488
|
|
468
|
-
app.
|
469
|
-
|
470
|
-
app.halt(@stats)
|
489
|
+
app.halt_code(@stats).should == 4
|
471
490
|
end
|
472
491
|
end
|
473
492
|
|
@@ -573,8 +592,8 @@ module MCollective
|
|
573
592
|
e.stubs(:backtrace).returns(["rspec"])
|
574
593
|
e.stubs(:to_s).returns("rspec")
|
575
594
|
|
576
|
-
@app.expects(:options).returns({:verbose => true}).
|
577
|
-
out.expects(:puts).with(regexp_matches(/ application failed to run
|
595
|
+
@app.expects(:options).returns({:verbose => true}).times(3)
|
596
|
+
out.expects(:puts).with(regexp_matches(/ application failed to run/))
|
578
597
|
out.expects(:puts).with(regexp_matches(/from rspec <---/))
|
579
598
|
out.expects(:puts).with(regexp_matches(/rspec.+Mocha::Mock/))
|
580
599
|
|
data/spec/unit/cache_spec.rb
CHANGED
@@ -76,14 +76,14 @@ module MCollective
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
describe "#
|
80
|
-
it "should return
|
79
|
+
describe "#ttl" do
|
80
|
+
it "should return a positive value for an unexpired item" do
|
81
81
|
Cache.setup("rspec", 300)
|
82
82
|
Cache.write("rspec", :key, :val)
|
83
83
|
Cache.ttl("rspec", :key).should >= 0
|
84
84
|
end
|
85
85
|
|
86
|
-
it "should return <0 for
|
86
|
+
it "should return <0 for an expired item" do
|
87
87
|
Cache.setup("rspec", 300)
|
88
88
|
Cache.write("rspec", :key, :val)
|
89
89
|
|
data/spec/unit/client_spec.rb
CHANGED
@@ -27,44 +27,122 @@ module MCollective
|
|
27
27
|
|
28
28
|
describe "#sendreq" do
|
29
29
|
it "should send the supplied message" do
|
30
|
+
request = mock
|
31
|
+
request.stubs(:agent)
|
32
|
+
request.stubs(:ttl)
|
33
|
+
request.stubs(:collective)
|
34
|
+
@client.expects(:createreq).with(request, "rspec", {}).returns(request)
|
35
|
+
request.expects(:publish)
|
36
|
+
request.expects(:requestid).returns("13fegbcw").twice
|
37
|
+
result = @client.sendreq(request, "rspec")
|
38
|
+
result.should == "13fegbcw"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#createreq" do
|
43
|
+
it "should create a request" do
|
30
44
|
message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
|
45
|
+
message.stubs(:encode!)
|
46
|
+
@client.stubs(:subscribe)
|
47
|
+
message.stubs(:reply_to)
|
48
|
+
result = @client.createreq(message, "rspec")
|
49
|
+
result.should == message
|
50
|
+
end
|
31
51
|
|
32
|
-
|
33
|
-
|
34
|
-
message.
|
35
|
-
|
36
|
-
|
52
|
+
it "should create a new request if the message if not of type Message" do
|
53
|
+
message = mock
|
54
|
+
message.stubs(:encode!)
|
55
|
+
@client.stubs(:subscribe)
|
56
|
+
message.stubs(:reply_to)
|
57
|
+
Message.expects(:new).returns(message)
|
58
|
+
result = @client.createreq("message", "rspec")
|
59
|
+
result.should == message
|
37
60
|
end
|
38
61
|
|
39
|
-
it "should
|
62
|
+
it "should subscripe to the reply queue unless has been specified" do
|
40
63
|
message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
|
41
|
-
message.
|
64
|
+
message.stubs(:encode!)
|
65
|
+
@client.expects(:subscribe).with("rspec", :reply)
|
66
|
+
message.stubs(:reply_to).returns(nil)
|
67
|
+
@client.createreq(message, "rspec")
|
68
|
+
end
|
42
69
|
|
43
|
-
|
70
|
+
it "should not subscribe to the reply queue if one has been specified" do
|
71
|
+
message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
|
72
|
+
message.stubs(:encode!)
|
44
73
|
@client.expects(:subscribe).never
|
45
|
-
message.
|
46
|
-
|
47
|
-
@client.sendreq(message, "rspec")
|
74
|
+
message.stubs(:reply_to).returns(:reply)
|
75
|
+
@client.createreq(message, "rspec")
|
48
76
|
end
|
49
77
|
end
|
50
|
-
describe "#req" do
|
51
|
-
it "should record the requestid" do
|
52
|
-
message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
|
53
|
-
message.discovered_hosts = ["rspec"]
|
54
78
|
|
55
|
-
|
56
|
-
|
79
|
+
describe "#subscribe" do
|
80
|
+
it "should subscribe to a destination if it hasn't already" do
|
81
|
+
subscription = mock
|
82
|
+
Util.stubs(:make_subscriptions).returns(subscription)
|
83
|
+
Util.expects(:subscribe).with(subscription)
|
84
|
+
@client.subscribe("rspec", :queue)
|
85
|
+
@client.instance_variable_get(:@subscriptions).should == {"rspec" => 1}
|
86
|
+
end
|
57
87
|
|
58
|
-
|
59
|
-
@client.
|
88
|
+
it "should not subscribe to a destination if it already has" do
|
89
|
+
@client.instance_variable_get(:@subscriptions)["rspec"] = 1
|
90
|
+
Util.expects(:make_subscription).never
|
91
|
+
@client.subscribe("rspec", :queue)
|
92
|
+
end
|
93
|
+
end
|
60
94
|
|
61
|
-
|
95
|
+
describe "#unsubscribe" do
|
96
|
+
it "should unsubscribe if a subscription has been made" do
|
97
|
+
subscription = mock
|
98
|
+
@client.instance_variable_get(:@subscriptions)["rspec"] = 1
|
99
|
+
Util.expects(:make_subscriptions).returns(subscription)
|
100
|
+
Util.expects(:unsubscribe).with(subscription)
|
101
|
+
@client.unsubscribe("rspec", :queue)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should no unsubscribe if a subscription hasn't been made" do
|
105
|
+
Util.expects(:make_subscription).never
|
106
|
+
@client.unsubscribe("rspec", :queue)
|
107
|
+
end
|
108
|
+
end
|
62
109
|
|
63
|
-
|
110
|
+
describe "receive" do
|
111
|
+
let(:message) do
|
112
|
+
m = mock
|
113
|
+
m.stubs(:type=)
|
114
|
+
m.stubs(:expected_msgid=)
|
115
|
+
m.stubs(:decode!)
|
116
|
+
m.stubs(:requestid).returns("erfs123")
|
117
|
+
m
|
118
|
+
end
|
119
|
+
|
120
|
+
let(:badmessage) do
|
121
|
+
m = mock
|
122
|
+
m.stubs(:type=)
|
123
|
+
m.stubs(:expected_msgid=)
|
124
|
+
m.stubs(:decode!)
|
125
|
+
m.stubs(:requestid).returns("badmessage")
|
126
|
+
m
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should receive a message" do
|
130
|
+
@connector.stubs(:receive).returns(message)
|
131
|
+
result = @client.receive("erfs123")
|
132
|
+
result.should == message
|
133
|
+
end
|
134
|
+
|
135
|
+
it "log and retry if the message reqid does not match the expected msgid" do
|
136
|
+
Log.expects(:debug).with("Ignoring a message for some other client : Message reqid badmessage does not match our reqid erfs123")
|
137
|
+
@connector.stubs(:receive).returns(badmessage, message)
|
138
|
+
@client.receive("erfs123")
|
139
|
+
end
|
64
140
|
|
65
|
-
|
66
|
-
|
67
|
-
|
141
|
+
it "should log and retry if a SecurityValidationFailed expection is raised" do
|
142
|
+
Log.expects(:warn).with("Ignoring a message that did not pass security validations")
|
143
|
+
badmessage.stubs(:decode!).raises(SecurityValidationFailed)
|
144
|
+
@connector.stubs(:receive).returns(badmessage, message)
|
145
|
+
@client.receive("erfs123")
|
68
146
|
end
|
69
147
|
end
|
70
148
|
|
@@ -74,5 +152,172 @@ module MCollective
|
|
74
152
|
@client.discover({}, 1).should == []
|
75
153
|
end
|
76
154
|
end
|
155
|
+
|
156
|
+
describe "#req" do
|
157
|
+
let(:message) do
|
158
|
+
m = Message.new("rspec", nil, {:agent => "rspec",
|
159
|
+
:type => :request,
|
160
|
+
:collective => "mcollective",
|
161
|
+
:filter => Util.empty_filter,
|
162
|
+
:options => Util.default_options})
|
163
|
+
m.discovered_hosts = ["rspec"]
|
164
|
+
m
|
165
|
+
end
|
166
|
+
|
167
|
+
let(:request) do
|
168
|
+
r = mock
|
169
|
+
r.stubs(:requestid).returns("erfs123")
|
170
|
+
r
|
171
|
+
end
|
172
|
+
|
173
|
+
before :each do
|
174
|
+
@client.expects(:unsubscribe)
|
175
|
+
@discoverer.expects(:discovery_timeout).with(message.options[:timeout], message.options[:filter]).returns(0)
|
176
|
+
@client.stubs(:createreq).returns(request)
|
177
|
+
@client.expects(:update_stat)
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should thread the publisher and receiver if configured" do
|
181
|
+
@client.instance_variable_get(:@options)[:threaded] = true
|
182
|
+
@client.expects(:threaded_req).with(request, nil, 0, 1)
|
183
|
+
message.options[:threaded] = true
|
184
|
+
@client.req(message)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should not thread the publisher and receiver if configured" do
|
188
|
+
@client.instance_variable_set(:@threaded, false)
|
189
|
+
@client.expects(:unthreaded_req).with(request, nil, 0, 1)
|
190
|
+
@client.req(message)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "#unthreaded_req" do
|
195
|
+
it "should start a publisher and then start a receiver" do
|
196
|
+
request = mock
|
197
|
+
request.stubs(:requestid).returns("erfs123")
|
198
|
+
@client.expects(:start_publisher).with(request, 5)
|
199
|
+
@client.expects(:start_receiver).with("erfs123", 2, 10)
|
200
|
+
@client.unthreaded_req(request, 5, 10, 2)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "#threaded_req" do
|
205
|
+
it "should start a publisher thread and a receiver thread" do
|
206
|
+
request = mock
|
207
|
+
request.stubs(:requestid).returns("erfs123")
|
208
|
+
p_thread = mock
|
209
|
+
r_thread = mock
|
210
|
+
Thread.expects(:new).yields.returns(p_thread)
|
211
|
+
Thread.expects(:new).yields.returns(r_thread)
|
212
|
+
@client.expects(:start_publisher).with(request, 5)
|
213
|
+
@client.expects(:start_receiver).with("erfs123", 2, 15).returns(2)
|
214
|
+
p_thread.expects(:join)
|
215
|
+
result = @client.threaded_req(request, 5, 10, 2)
|
216
|
+
result.should == 2
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "#start_publisher" do
|
221
|
+
let(:message) do
|
222
|
+
m = mock
|
223
|
+
m.stubs(:requestid)
|
224
|
+
m.stubs(:agent)
|
225
|
+
m.stubs(:ttl)
|
226
|
+
m.stubs(:collective)
|
227
|
+
m
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should publish the message" do
|
231
|
+
Timeout.stubs(:timeout).with(2).yields
|
232
|
+
message.expects(:publish)
|
233
|
+
@client.start_publisher(message, 2)
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should log a warning on a timeout" do
|
237
|
+
Timeout.stubs(:timeout).raises(Timeout::Error)
|
238
|
+
Log.expects(:warn).with("Could not publish all messages. Publishing timed out.")
|
239
|
+
@client.start_publisher(message,2)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "#start_receiver" do
|
244
|
+
it "should go into a receive loop and receive until it reaches waitfor" do
|
245
|
+
results = []
|
246
|
+
Timeout.stubs(:timeout).yields
|
247
|
+
message = mock
|
248
|
+
@client.stubs(:receive).with("erfs123").returns(message)
|
249
|
+
message.stubs(:payload).returns("msg1", "msg2", "msg3")
|
250
|
+
@client.start_receiver("erfs123", 3, 5) do |msg|
|
251
|
+
results << msg
|
252
|
+
end
|
253
|
+
results.should == ["msg1", "msg2", "msg3"]
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should log a warning if a timeout occurs" do
|
257
|
+
results = []
|
258
|
+
Timeout.stubs(:timeout).yields
|
259
|
+
message = mock
|
260
|
+
@client.stubs(:receive).with("erfs123").returns(message)
|
261
|
+
message.stubs(:payload).returns("msg1", "msg2", "timeout")
|
262
|
+
Log.expects(:warn).with("Could not receive all responses. Expected : 3. Received : 2")
|
263
|
+
responded = @client.start_receiver("erfs123", 3, 5) do |msg|
|
264
|
+
if msg == "timeout"
|
265
|
+
raise Timeout::Error
|
266
|
+
end
|
267
|
+
results << msg
|
268
|
+
end
|
269
|
+
results.should == ["msg1", "msg2"]
|
270
|
+
responded.should == 2
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should not log a warning if a the response count is larger or equal to the expected number of responses" do
|
274
|
+
results = []
|
275
|
+
Timeout.stubs(:timeout).yields
|
276
|
+
message = mock
|
277
|
+
@client.stubs(:receive).with("erfs123").returns(message)
|
278
|
+
message.stubs(:payload).returns("msg1", "msg2", "timeout")
|
279
|
+
Log.expects(:warn).never
|
280
|
+
responded = @client.start_receiver("erfs123", 2, 5) do |msg|
|
281
|
+
if msg == "timeout"
|
282
|
+
raise Timeout::Error
|
283
|
+
end
|
284
|
+
results << msg
|
285
|
+
end
|
286
|
+
results.should == ["msg1", "msg2"]
|
287
|
+
responded.should == 2
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "#update_stat" do
|
292
|
+
let(:before) do
|
293
|
+
{ :starttime => Time.now.to_f,
|
294
|
+
:discoverytime => 0,
|
295
|
+
:blocktime => 0,
|
296
|
+
:totaltime => 0 }
|
297
|
+
end
|
298
|
+
|
299
|
+
let(:after) do
|
300
|
+
{ :starttime => 10.0,
|
301
|
+
:discoverytime => 0,
|
302
|
+
:blocktime => 10.0,
|
303
|
+
:totaltime => 10.0,
|
304
|
+
:responses => 5,
|
305
|
+
:requestid => "erfs123",
|
306
|
+
:noresponsefrom => [] }
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should update stats and return the stats hash" do
|
310
|
+
Time.stubs(:now).returns(10, 20)
|
311
|
+
@client.update_stat(before, 5, "erfs123").should == after
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe "#discovered_req" do
|
316
|
+
it "should raise a deprecation exception" do
|
317
|
+
expect{
|
318
|
+
@client.discovered_req(nil, nil)
|
319
|
+
}.to raise_error("Client#discovered_req has been removed, please port your agent and client to the SimpleRPC framework")
|
320
|
+
end
|
321
|
+
end
|
77
322
|
end
|
78
323
|
end
|