right_agent 2.4.3 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -1
- data/Rakefile +48 -57
- data/lib/right_agent/clients/api_client.rb +2 -2
- data/lib/right_agent/clients/balanced_http_client.rb +1 -1
- data/lib/right_agent/clients/router_client.rb +11 -2
- data/lib/right_agent/history.rb +1 -1
- data/lib/right_agent/monkey_patches/ruby_patch.rb +1 -0
- data/lib/right_agent/monkey_patches/ruby_patch/json_patch.rb +43 -0
- data/lib/right_agent/serialize/serializer.rb +1 -10
- data/right_agent.gemspec +2 -2
- data/spec/clients/api_client_spec.rb +5 -1
- data/spec/clients/balanced_http_client_spec.rb +7 -4
- data/spec/clients/blocking_client_spec.rb +2 -1
- data/spec/clients/router_client_spec.rb +18 -9
- data/spec/clients/spec_helper.rb +37 -5
- data/spec/retryable_request_spec.rb +18 -24
- data/spec/spec_helper.rb +2 -1
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
"master" branch: {<img src="https://travis-ci.org/rightscale/right_agent.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/rightscale/right_agent]
|
2
|
+
|
1
3
|
= RightAgent
|
2
4
|
|
3
5
|
= DESCRIPTION
|
@@ -22,7 +24,7 @@ documentation.
|
|
22
24
|
Also use the built-in issues tracker (https://github.com/rightscale/right_agent/issues)
|
23
25
|
to report issues.
|
24
26
|
|
25
|
-
Maintained by the RightScale
|
27
|
+
Maintained by the RightScale Cornsilk Team
|
26
28
|
|
27
29
|
== Interface
|
28
30
|
|
data/Rakefile
CHANGED
@@ -23,16 +23,48 @@
|
|
23
23
|
|
24
24
|
require 'rubygems'
|
25
25
|
require 'bundler/setup'
|
26
|
-
|
26
|
+
|
27
27
|
require 'rake'
|
28
|
-
require '
|
29
|
-
require 'rake/rdoctask'
|
30
|
-
require 'rake/gempackagetask'
|
28
|
+
require 'rubygems/package_task'
|
31
29
|
require 'rake/clean'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
require 'fileutils'
|
32
32
|
|
33
|
-
|
33
|
+
# These dependencies can be omitted using "bundle install --without"; tolerate their absence.
|
34
|
+
['rdoc/task'].each do |optional|
|
35
|
+
begin
|
36
|
+
require optional
|
37
|
+
rescue LoadError
|
38
|
+
# ignore
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
spec_opts_file = "\"#{File.dirname(__FILE__)}/spec/spec.opts\""
|
43
|
+
spec_opts_file = "\"#{File.dirname(__FILE__)}/spec/spec.win32.opts\"" if RUBY_PLATFORM =~ /mingw|mswin32/
|
44
|
+
RSPEC_OPTS = ['--options', spec_opts_file]
|
45
|
+
|
46
|
+
desc "Run unit tests"
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
desc 'Run unit tests'
|
50
|
+
RSpec::Core::RakeTask.new do |t|
|
51
|
+
t.rspec_opts = RSPEC_OPTS
|
52
|
+
t.pattern = Dir['**/*_spec.rb']
|
53
|
+
end
|
54
|
+
|
55
|
+
if defined?(Rake::RDocTask)
|
56
|
+
desc 'Generate documentation for the right_agent gem.'
|
57
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
58
|
+
rdoc.rdoc_dir = 'doc'
|
59
|
+
rdoc.title = 'RightAgent'
|
60
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
61
|
+
rdoc.rdoc_files.include('README.rdoc')
|
62
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
63
|
+
rdoc.rdoc_files.exclude('spec/**/*')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
CLEAN.include('doc')
|
34
67
|
|
35
|
-
# == Gem packaging == #
|
36
68
|
module RightScale
|
37
69
|
class MultiPlatformGemTask
|
38
70
|
def self.gem_platform_override
|
@@ -50,64 +82,23 @@ module RightScale
|
|
50
82
|
end
|
51
83
|
end
|
52
84
|
|
53
|
-
#
|
54
|
-
# platform value.
|
55
|
-
# redefining them, so accumulated gem tasks will gem up all platforms.
|
85
|
+
# Multiply define gem and package task(s) using a gemspec with overridden gem
|
86
|
+
# platform value. This works because rake accumulates task actions instead of
|
87
|
+
# redefining them, so accumulated gem tasks will gem up all platforms. We need
|
56
88
|
# to produce multiple platform-specific .gem files because otherwise the gem
|
57
89
|
# dependencies for non-Linux platforms (i.e. Windows) are lost from the default
|
58
90
|
# .gem file produced on a Linux platform.
|
59
91
|
gemtask = nil
|
60
92
|
::RightScale::MultiPlatformGemTask.define(%w[linux mingw], 'right_agent.gemspec') do |spec|
|
61
|
-
gemtask = ::
|
62
|
-
|
93
|
+
gemtask = Gem::PackageTask.new(spec) do |pkg|
|
94
|
+
pkg.package_dir = 'pkg'
|
63
95
|
|
64
96
|
# the following are used by 'package' task (but not by 'gem' task)
|
65
|
-
|
66
|
-
|
97
|
+
pkg.need_zip = !`which zip`.strip.empty? # not present on Windows by default
|
98
|
+
pkg.need_tar = true # some form of tar is required on Windows and Linux
|
67
99
|
end
|
68
100
|
end
|
101
|
+
CLEAN.include('pkg')
|
69
102
|
|
70
|
-
|
71
|
-
|
72
|
-
CLEAN.include(gemtask.package_dir)
|
73
|
-
|
74
|
-
# == Unit tests == #
|
75
|
-
spec_opts_file = "\"#{File.dirname(__FILE__)}/spec/spec.opts\""
|
76
|
-
spec_opts_file = "\"#{File.dirname(__FILE__)}/spec/spec.win32.opts\"" if RUBY_PLATFORM =~ /mingw|mswin32/
|
77
|
-
RSPEC_OPTS = ['--options', spec_opts_file]
|
78
|
-
|
79
|
-
desc 'Run unit tests'
|
80
|
-
RSpec::Core::RakeTask.new do |t|
|
81
|
-
t.rspec_opts = RSPEC_OPTS
|
82
|
-
end
|
83
|
-
|
84
|
-
namespace :spec do
|
85
|
-
desc 'Run unit tests with RCov'
|
86
|
-
RSpec::Core::RakeTask.new(:rcov) do |t|
|
87
|
-
t.rspec_opts = RSPEC_OPTS
|
88
|
-
t.rcov = true
|
89
|
-
t.rcov_opts = %q[--exclude "spec"]
|
90
|
-
end
|
91
|
-
|
92
|
-
desc 'Print Specdoc for all unit tests'
|
93
|
-
RSpec::Core::RakeTask.new(:doc) do |t|
|
94
|
-
t.rspec_opts = ["--format", "documentation"]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# == Documentation == #
|
99
|
-
|
100
|
-
desc 'Generate API documentation to doc/rdocs/index.html'
|
101
|
-
Rake::RDocTask.new do |rd|
|
102
|
-
rd.rdoc_dir = 'doc/rdocs'
|
103
|
-
rd.main = 'README.rdoc'
|
104
|
-
rd.rdoc_files.include 'README.rdoc', 'lib/**/*.rb'
|
105
|
-
end
|
106
|
-
CLEAN.include('doc/rdocs')
|
107
|
-
|
108
|
-
# == Emacs integration ==
|
109
|
-
|
110
|
-
desc 'Rebuild TAGS file for emacs'
|
111
|
-
task :tags do
|
112
|
-
sh 'rtags -R lib spec'
|
113
|
-
end
|
103
|
+
require 'right_develop'
|
104
|
+
RightDevelop::CI::RakeTask.new
|
@@ -339,8 +339,8 @@ module RightScale
|
|
339
339
|
end
|
340
340
|
|
341
341
|
# Truncate string if it exceeds maximum length
|
342
|
-
# Do length check with bytesize rather than size since this
|
343
|
-
# is
|
342
|
+
# Do length check with bytesize rather than size since this method
|
343
|
+
# is only intended for use with ruby 1.9 and above, otherwise
|
344
344
|
# multi-byte characters could cause this code to be too lenient
|
345
345
|
#
|
346
346
|
# @param [String, NilClass] value to be truncated
|
@@ -445,7 +445,7 @@ module RightScale
|
|
445
445
|
elsif code == 204 || body.nil? || (body.respond_to?(:empty?) && body.empty?)
|
446
446
|
result = nil
|
447
447
|
elsif decode
|
448
|
-
result = JSON.
|
448
|
+
result = JSON.legacy_load(body)
|
449
449
|
result = nil if result.respond_to?(:empty?) && result.empty?
|
450
450
|
else
|
451
451
|
result = body
|
@@ -474,7 +474,16 @@ module RightScale
|
|
474
474
|
@websocket = Faye::WebSocket::Client.new(url.to_s, protocols = nil, options)
|
475
475
|
|
476
476
|
@websocket.onerror = lambda do |event|
|
477
|
-
|
477
|
+
error = if event.respond_to?(:data)
|
478
|
+
# faye-websocket 0.7.0
|
479
|
+
event.data
|
480
|
+
elsif event.respond_to?(:message)
|
481
|
+
# faye-websocket 0.7.4
|
482
|
+
event.message
|
483
|
+
else
|
484
|
+
event.to_s
|
485
|
+
end
|
486
|
+
ErrorTracker.log(self, "WebSocket error (#{error})") if error
|
478
487
|
end
|
479
488
|
|
480
489
|
@websocket.onclose = lambda do |event|
|
@@ -493,7 +502,7 @@ module RightScale
|
|
493
502
|
@websocket.onmessage = lambda do |event|
|
494
503
|
begin
|
495
504
|
# Receive event
|
496
|
-
event = SerializationHelper.symbolize_keys(JSON.
|
505
|
+
event = SerializationHelper.symbolize_keys(JSON.parser.new(event.data, JSON.load_default_options).parse)
|
497
506
|
Log.info("Received EVENT <#{event[:uuid]}> #{event[:type]} #{event[:path]} from #{event[:from]}")
|
498
507
|
@stats["events"].update("#{event[:type]} #{event[:path]}")
|
499
508
|
|
data/lib/right_agent/history.rb
CHANGED
@@ -62,7 +62,7 @@ module RightScale
|
|
62
62
|
# where String is the event name and Object is any associated JSON-encodable data
|
63
63
|
def load
|
64
64
|
events = []
|
65
|
-
File.open(@history, "r") { |f| events = f.readlines.map { |l| JSON.
|
65
|
+
File.open(@history, "r") { |f| events = f.readlines.map { |l| JSON.legacy_load(l) } } if File.readable?(@history)
|
66
66
|
events
|
67
67
|
end
|
68
68
|
|
@@ -51,5 +51,6 @@ RIGHT_AGENT_RUBY_PATCH_BASE_DIR = ::File.normalize_path('../ruby_patch', __FILE_
|
|
51
51
|
|
52
52
|
require File.join(RIGHT_AGENT_RUBY_PATCH_BASE_DIR, 'array_patch')
|
53
53
|
require File.join(RIGHT_AGENT_RUBY_PATCH_BASE_DIR, 'object_patch')
|
54
|
+
require File.join(RIGHT_AGENT_RUBY_PATCH_BASE_DIR, 'json_patch')
|
54
55
|
|
55
56
|
end # Unless already defined
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
module JSON
|
24
|
+
class << self
|
25
|
+
def legacy_load(source)
|
26
|
+
if source.respond_to? :to_str
|
27
|
+
source = source.to_str
|
28
|
+
elsif source.respond_to? :to_io
|
29
|
+
source = source.to_io.read
|
30
|
+
else
|
31
|
+
source = source.read
|
32
|
+
end
|
33
|
+
source = source.dup.force_encoding("UTF-8") if source.respond_to?(:force_encoding)
|
34
|
+
if source =~ /(.*)json_class":"Nanite::(.*)/
|
35
|
+
source = Regexp.last_match(1) + 'json_class":"RightScale::' + Regexp.last_match(2)
|
36
|
+
end
|
37
|
+
# Workaround to make RightLink MessageEncoder work after chef update to 14.11
|
38
|
+
# which uses ffi-yajl which monkey patch JSON module and decoding of serialazed Ruby objects
|
39
|
+
# doesn't works as expected
|
40
|
+
JSON.parser.new(source, JSON.load_default_options).parse
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -29,16 +29,7 @@ require File.normalize_path(File.join(File.dirname(__FILE__), 'message_pack'))
|
|
29
29
|
|
30
30
|
module JSONSerializer
|
31
31
|
def self.load(source)
|
32
|
-
|
33
|
-
if source.respond_to? :to_str
|
34
|
-
source = source.to_str
|
35
|
-
elsif source.respond_to? :to_io
|
36
|
-
source = source.to_io.read
|
37
|
-
else
|
38
|
-
source = source.read
|
39
|
-
end
|
40
|
-
source.force_encoding("UTF-8") if source.respond_to?(:force_encoding)
|
41
|
-
JSON.load(source)
|
32
|
+
JSON.legacy_load(source)
|
42
33
|
end
|
43
34
|
|
44
35
|
def self.dump(*args)
|
data/right_agent.gemspec
CHANGED
@@ -25,8 +25,8 @@ require 'rbconfig'
|
|
25
25
|
|
26
26
|
Gem::Specification.new do |spec|
|
27
27
|
spec.name = 'right_agent'
|
28
|
-
spec.version = '2.4.
|
29
|
-
spec.date = '2014-10-
|
28
|
+
spec.version = '2.4.4'
|
29
|
+
spec.date = '2014-10-23'
|
30
30
|
spec.authors = ['Lee Kirchhoff', 'Raphael Simon', 'Tony Spataro', 'Scott Messier']
|
31
31
|
spec.email = 'lee@rightscale.com'
|
32
32
|
spec.homepage = 'https://github.com/rightscale/right_agent'
|
@@ -406,7 +406,11 @@ describe RightScale::ApiClient do
|
|
406
406
|
|
407
407
|
it "accounts for multi-byte characters" do
|
408
408
|
@client.send(:truncate, "Schös Tägli wünschi", 20).should == "Schös Tägli wü..."
|
409
|
-
|
409
|
+
if RUBY_VERSION =~ /^1\.8/
|
410
|
+
@client.send(:truncate, "Schös Tägli wünschi", 20).should == "Schös Tägli wü..."
|
411
|
+
else
|
412
|
+
@client.send(:truncate, "Schös Tägli wünschi", 19).should == "Schös Tägli w..."
|
413
|
+
end
|
410
414
|
@client.send(:truncate, "Schös Tägli wünschi", 18).should == "Schös Tägli w..."
|
411
415
|
@client.send(:truncate, "Schös Tägli wünschi", 17).should == "Schös Tägli ..."
|
412
416
|
end
|
@@ -158,7 +158,7 @@ describe RightScale::BalancedHttpClient do
|
|
158
158
|
it "appends specified filter parameters to list when Log.level is :debug" do
|
159
159
|
@params = {:some => "data", :secret => "data", :other => "data"}
|
160
160
|
@log.should_receive(:level).and_return(:debug)
|
161
|
-
@log.should_receive(:info).with(
|
161
|
+
@log.should_receive(:info).with(on { |a| a =~ /^Requesting POST/ && a =~ /some.*data/ && a =~ /secret.*hidden/ && a =~ /other.*hidden/ }).once
|
162
162
|
@log.should_receive(:info).with("Completed <random uuid> in 10ms | 200 [http://my.com/foo/bar] | 11 bytes | {\"out\"=>123}").once
|
163
163
|
@client.request(:post, @path, @params, :filter_params => [:other])
|
164
164
|
end
|
@@ -533,20 +533,23 @@ describe RightScale::BalancedHttpClient do
|
|
533
533
|
it "generates text containing containing host, path, and filtered parameters" do
|
534
534
|
@log.should_receive(:level).and_return(:debug)
|
535
535
|
text = @client.send(:log_text, @path, {:some => "data", :secret => "data"}, ["secret"], @url)
|
536
|
-
text
|
536
|
+
(text == "[http://my.com/foo/bar {:some=>\"data\", :secret=>\"<hidden>\"}]" ||
|
537
|
+
text == "[http://my.com/foo/bar {:secret=>\"<hidden>\", :some=>\"data\"}]").should be true
|
537
538
|
end
|
538
539
|
end
|
539
540
|
|
540
541
|
context "when exception" do
|
541
542
|
it "includes params regardless of Log.level" do
|
542
543
|
text = @client.send(:log_text, @path, {:some => "data", :secret => "data"}, ["secret"], @url, "failed")
|
543
|
-
text
|
544
|
+
(text == "[http://my.com/foo/bar {:some=>\"data\", :secret=>\"<hidden>\"}] | failed" ||
|
545
|
+
text == "[http://my.com/foo/bar {:secret=>\"<hidden>\", :some=>\"data\"}] | failed").should be true
|
544
546
|
end
|
545
547
|
|
546
548
|
it "includes exception text" do
|
547
549
|
exception = RightScale::HttpExceptions.create(400, "bad data")
|
548
550
|
text = @client.send(:log_text, @path, {:some => "data", :secret => "data"}, ["secret"], @url, exception)
|
549
|
-
text
|
551
|
+
(text == "[http://my.com/foo/bar {:some=>\"data\", :secret=>\"<hidden>\"}] | 400 Bad Request: bad data" ||
|
552
|
+
text == "[http://my.com/foo/bar {:secret=>\"<hidden>\", :some=>\"data\"}] | 400 Bad Request: bad data").should be true
|
550
553
|
end
|
551
554
|
end
|
552
555
|
end
|
@@ -151,7 +151,8 @@ describe RightScale::BlockingClient do
|
|
151
151
|
it "uses form-encoded query option for parameters" do
|
152
152
|
@params = {:some => "data", :more => ["a", "b"]}
|
153
153
|
_, request_options = @client.options(verb, @path, @params, @headers, @options)
|
154
|
-
request_options[:query]
|
154
|
+
query = request_options[:query]
|
155
|
+
(query == "?some=data&more[]=a&more[]=b" || query == "?more[]=a&more[]=b&some=data").should be true
|
155
156
|
request_options[:payload].should be nil
|
156
157
|
end
|
157
158
|
|
@@ -585,16 +585,25 @@ describe RightScale::RouterClient do
|
|
585
585
|
end
|
586
586
|
|
587
587
|
context "on error" do
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
588
|
+
["0.7.0", "0.7.4"].each do |version|
|
589
|
+
context "in faye-websocket #{version}" do
|
590
|
+
before(:each) do
|
591
|
+
@websocket = WebSocketClientMock.new(version)
|
592
|
+
flexmock(Faye::WebSocket::Client).should_receive(:new).and_return(@websocket)
|
593
|
+
end
|
593
594
|
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
595
|
+
it "logs error" do
|
596
|
+
@log.should_receive(:error).with("WebSocket error (Protocol Error)")
|
597
|
+
@client.send(:connect, @routing_keys, &@handler)
|
598
|
+
@websocket.onerror("Protocol Error")
|
599
|
+
end
|
600
|
+
|
601
|
+
it "does not log if there is no error data" do
|
602
|
+
@log.should_receive(:error).never
|
603
|
+
@client.send(:connect, @routing_keys, &@handler)
|
604
|
+
@websocket.onerror(nil)
|
605
|
+
end
|
606
|
+
end
|
598
607
|
end
|
599
608
|
end
|
600
609
|
end
|
data/spec/clients/spec_helper.rb
CHANGED
@@ -57,7 +57,7 @@ class AuthClientMock < RightScale::AuthClient
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
# Mock WebSocket event
|
60
|
+
# Mock WebSocket event per faye-websocket 0.7.0
|
61
61
|
class WebSocketEventMock
|
62
62
|
attr_reader :code, :data, :reason
|
63
63
|
|
@@ -68,10 +68,42 @@ class WebSocketEventMock
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
# Mock WebSocket message event per faye-websocket 0.7.4
|
72
|
+
class WebSocketMessageEventMock
|
73
|
+
attr_reader :data
|
74
|
+
|
75
|
+
def initialize(data)
|
76
|
+
@data = data
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Mock WebSocket close event per faye-websocket 0.7.4
|
81
|
+
class WebSocketCloseEventMock
|
82
|
+
attr_reader :code, :reason
|
83
|
+
|
84
|
+
def initialize(code = nil, reason = nil)
|
85
|
+
@code = code
|
86
|
+
@reason = reason
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Mock WebSocket error event per faye-websocket 0.7.4
|
91
|
+
class WebSocketErrorEventMock
|
92
|
+
attr_reader :message
|
93
|
+
|
94
|
+
def initialize(message = nil)
|
95
|
+
@message = message
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
71
99
|
# Mock of WebSocket so that can call on methods
|
72
100
|
class WebSocketClientMock
|
73
101
|
attr_reader :sent, :closed, :code, :reason
|
74
102
|
|
103
|
+
def initialize(version = "0.7.4")
|
104
|
+
@version = version
|
105
|
+
end
|
106
|
+
|
75
107
|
def send(event)
|
76
108
|
@sent = @sent.nil? ? event : (@sent.is_a?(Array) ? @sent << event : [@sent, event])
|
77
109
|
end
|
@@ -87,7 +119,7 @@ class WebSocketClientMock
|
|
87
119
|
end
|
88
120
|
|
89
121
|
def onclose(code, reason = nil)
|
90
|
-
@event = WebSocketEventMock.new(nil, code, reason)
|
122
|
+
@event = @version == "0.7.4" ? WebSocketCloseEventMock.new(code, reason) : WebSocketEventMock.new(nil, code, reason)
|
91
123
|
@close_block.call(@event)
|
92
124
|
end
|
93
125
|
|
@@ -95,8 +127,8 @@ class WebSocketClientMock
|
|
95
127
|
@error_block = block
|
96
128
|
end
|
97
129
|
|
98
|
-
def onerror(
|
99
|
-
@event = WebSocketEventMock.new(
|
130
|
+
def onerror(message)
|
131
|
+
@event = @version == "0.7.4" ? WebSocketErrorEventMock.new(message) : WebSocketEventMock.new(message)
|
100
132
|
@error_block.call(@event)
|
101
133
|
end
|
102
134
|
|
@@ -105,7 +137,7 @@ class WebSocketClientMock
|
|
105
137
|
end
|
106
138
|
|
107
139
|
def onmessage(data)
|
108
|
-
@event = WebSocketEventMock.new(data)
|
140
|
+
@event = @version == "0.7.4" ? WebSocketMessageEventMock.new(data) : WebSocketEventMock.new(data)
|
109
141
|
@message_block.call(@event)
|
110
142
|
end
|
111
143
|
end
|
@@ -31,11 +31,10 @@ describe RightScale::RetryableRequest do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
before(:all) do
|
34
|
-
if @sender_exists = RightScale.const_defined?(:Sender)
|
34
|
+
if (@sender_exists = RightScale.const_defined?(:Sender))
|
35
35
|
RightScale.module_eval('OldSender = Sender')
|
36
36
|
end
|
37
37
|
RightScale.module_eval('Sender = SenderMock')
|
38
|
-
@options = {:time_to_live => RightScale::RetryableRequest::DEFAULT_TIMEOUT}
|
39
38
|
end
|
40
39
|
|
41
40
|
after(:all) do
|
@@ -44,6 +43,12 @@ describe RightScale::RetryableRequest do
|
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
46
|
+
before(:each) do
|
47
|
+
@now = Time.now
|
48
|
+
flexmock(Time).should_receive(:now).and_return(@now).by_default
|
49
|
+
@options = {:time_to_live => RightScale::RetryableRequest::DEFAULT_TIMEOUT}
|
50
|
+
end
|
51
|
+
|
47
52
|
context ':targets option' do
|
48
53
|
|
49
54
|
context 'when :targets => nil' do
|
@@ -51,8 +56,7 @@ describe RightScale::RetryableRequest do
|
|
51
56
|
request = RightScale::RetryableRequest.new('type', 'payload')
|
52
57
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, @options, Proc).
|
53
58
|
and_yield(RightScale::OperationResult.non_delivery('test')).once
|
54
|
-
flexmock(EM).should_receive(:add_timer).
|
55
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
59
|
+
flexmock(EM).should_receive(:add_timer).twice
|
56
60
|
request.run
|
57
61
|
end
|
58
62
|
end
|
@@ -62,8 +66,7 @@ describe RightScale::RetryableRequest do
|
|
62
66
|
request = RightScale::RetryableRequest.new('type', 'payload', :targets => ["rs-agent-1-1"])
|
63
67
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', {:agent_id => "rs-agent-1-1"}, @options, Proc).
|
64
68
|
and_yield(RightScale::OperationResult.non_delivery('test')).once
|
65
|
-
flexmock(EM).should_receive(:add_timer).
|
66
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
69
|
+
flexmock(EM).should_receive(:add_timer).twice
|
67
70
|
request.run
|
68
71
|
end
|
69
72
|
end
|
@@ -79,8 +82,7 @@ describe RightScale::RetryableRequest do
|
|
79
82
|
options[:time_to_live].should == @options[:time_to_live]
|
80
83
|
block.call(RightScale::OperationResult.non_delivery('test'))
|
81
84
|
end
|
82
|
-
flexmock(EM).should_receive(:add_timer).
|
83
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
85
|
+
flexmock(EM).should_receive(:add_timer).twice
|
84
86
|
request.run
|
85
87
|
end
|
86
88
|
end
|
@@ -105,8 +107,7 @@ describe RightScale::RetryableRequest do
|
|
105
107
|
request = RightScale::RetryableRequest.new('type', 'payload', :retry_on_error => true)
|
106
108
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, @options, Proc).
|
107
109
|
and_yield(RightScale::OperationResult.error('test')).once
|
108
|
-
flexmock(EM).should_receive(:add_timer).
|
109
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
110
|
+
flexmock(EM).should_receive(:add_timer).twice
|
110
111
|
request.run
|
111
112
|
end
|
112
113
|
|
@@ -117,8 +118,7 @@ describe RightScale::RetryableRequest do
|
|
117
118
|
end
|
118
119
|
flexmock(request).should_receive(:fail).never
|
119
120
|
flexmock(request).should_receive(:succeed).once
|
120
|
-
flexmock(EM).should_receive(:add_timer).
|
121
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
121
|
+
flexmock(EM).should_receive(:add_timer).once
|
122
122
|
request.run
|
123
123
|
end
|
124
124
|
|
@@ -127,8 +127,7 @@ describe RightScale::RetryableRequest do
|
|
127
127
|
flexmock(RightScale::Log).should_receive(:info).with("Request type canceled (enough already)").once
|
128
128
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, @options, Proc).
|
129
129
|
and_yield(RightScale::OperationResult.cancel('enough already')).once
|
130
|
-
flexmock(EM).should_receive(:add_timer).
|
131
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
130
|
+
flexmock(EM).should_receive(:add_timer).once
|
132
131
|
request.run
|
133
132
|
end
|
134
133
|
end
|
@@ -144,8 +143,7 @@ describe RightScale::RetryableRequest do
|
|
144
143
|
flexmock(RightScale::Log).should_receive(:info).with("Request non-delivery (test) for type").once
|
145
144
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, @options, Proc).
|
146
145
|
and_yield(RightScale::OperationResult.non_delivery('test')).once
|
147
|
-
flexmock(EM).should_receive(:add_timer).
|
148
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
146
|
+
flexmock(EM).should_receive(:add_timer).twice
|
149
147
|
request.run
|
150
148
|
end
|
151
149
|
|
@@ -155,8 +153,7 @@ describe RightScale::RetryableRequest do
|
|
155
153
|
flexmock(RightScale::Log).should_receive(:info).with("Request type failed (test) and should be retried").once
|
156
154
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, @options, Proc).
|
157
155
|
and_yield(RightScale::OperationResult.retry('test')).once
|
158
|
-
flexmock(EM).should_receive(:add_timer).
|
159
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
156
|
+
flexmock(EM).should_receive(:add_timer).twice
|
160
157
|
request.run
|
161
158
|
end
|
162
159
|
|
@@ -166,8 +163,7 @@ describe RightScale::RetryableRequest do
|
|
166
163
|
flexmock(RightScale::Log).should_receive(:info).with("Request type failed (RightScale not ready) and should be retried").once
|
167
164
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, @options, Proc).
|
168
165
|
and_yield(RightScale::OperationResult.retry).once
|
169
|
-
flexmock(EM).should_receive(:add_timer).
|
170
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).once
|
166
|
+
flexmock(EM).should_receive(:add_timer).twice
|
171
167
|
request.run
|
172
168
|
end
|
173
169
|
|
@@ -177,8 +173,7 @@ describe RightScale::RetryableRequest do
|
|
177
173
|
and_yield(RightScale::OperationResult.success('test')).once
|
178
174
|
flexmock(request).should_receive(:fail).once
|
179
175
|
flexmock(request).should_receive(:succeed).never
|
180
|
-
flexmock(EM).should_receive(:add_timer).
|
181
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
176
|
+
flexmock(EM).should_receive(:add_timer).once
|
182
177
|
request.cancel('test')
|
183
178
|
request.run
|
184
179
|
end
|
@@ -188,8 +183,7 @@ describe RightScale::RetryableRequest do
|
|
188
183
|
flexmock(RightScale::Log).should_receive(:info).with("Request type canceled (enough already)").once
|
189
184
|
flexmock(RightScale::Sender.instance).should_receive(:send_request).with('type', 'payload', nil, @options, Proc).
|
190
185
|
and_yield(RightScale::OperationResult.cancel('enough already')).once
|
191
|
-
flexmock(EM).should_receive(:add_timer).
|
192
|
-
flexmock(EM).should_receive(:add_timer).with(RightScale::RetryableRequest::DEFAULT_RETRY_DELAY, Proc).never
|
186
|
+
flexmock(EM).should_receive(:add_timer).once
|
193
187
|
request.run
|
194
188
|
end
|
195
189
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-10-
|
15
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: right_support
|
@@ -272,6 +272,7 @@ files:
|
|
272
272
|
- lib/right_agent/monkey_patches/ruby_patch.rb
|
273
273
|
- lib/right_agent/monkey_patches/ruby_patch/array_patch.rb
|
274
274
|
- lib/right_agent/monkey_patches/ruby_patch/darwin_patch.rb
|
275
|
+
- lib/right_agent/monkey_patches/ruby_patch/json_patch.rb
|
275
276
|
- lib/right_agent/monkey_patches/ruby_patch/linux_patch.rb
|
276
277
|
- lib/right_agent/monkey_patches/ruby_patch/linux_patch/file_patch.rb
|
277
278
|
- lib/right_agent/monkey_patches/ruby_patch/object_patch.rb
|
@@ -414,7 +415,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
414
415
|
version: '0'
|
415
416
|
segments:
|
416
417
|
- 0
|
417
|
-
hash:
|
418
|
+
hash: 2766248071266273264
|
418
419
|
requirements: []
|
419
420
|
rubyforge_project:
|
420
421
|
rubygems_version: 1.8.26
|