rorvswild 0.6.1 → 1.0.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -0
- data/README.md +70 -1
- data/lib/rorvswild.rb +15 -17
- data/lib/rorvswild/agent.rb +180 -0
- data/lib/rorvswild/client.rb +9 -285
- data/lib/rorvswild/installer.rb +0 -1
- data/lib/rorvswild/location.rb +10 -19
- data/lib/rorvswild/plugin/action_controller.rb +46 -0
- data/lib/rorvswild/plugin/action_mailer.rb +23 -0
- data/lib/rorvswild/plugin/action_view.rb +26 -0
- data/lib/rorvswild/plugin/active_job.rb +16 -0
- data/lib/rorvswild/plugin/active_record.rb +31 -0
- data/lib/rorvswild/plugin/delayed_job.rb +16 -0
- data/lib/rorvswild/plugin/mongo.rb +5 -4
- data/lib/rorvswild/plugin/net_http.rb +12 -2
- data/lib/rorvswild/plugin/redis.rb +1 -1
- data/lib/rorvswild/plugins.rb +14 -0
- data/lib/rorvswild/rails_loader.rb +1 -1
- data/lib/rorvswild/section.rb +54 -0
- data/lib/rorvswild/version.rb +1 -1
- data/test/helper.rb +13 -0
- data/test/measure_nested_sections_test.rb +38 -0
- data/test/plugin/action_controller_test.rb +58 -0
- data/test/plugin/action_mailer_test.rb +27 -0
- data/test/plugin/action_view_test.rb +40 -0
- data/test/plugin/active_job_test.rb +21 -0
- data/test/plugin/active_record_test.rb +39 -0
- data/test/plugin/delayed_job_test.rb +35 -0
- data/test/plugin/mongo_test.rb +9 -20
- data/test/plugin/net_http_test.rb +12 -23
- data/test/plugin/redis_test.rb +15 -27
- data/test/rorvswild_test.rb +141 -0
- data/test/run.rb +1 -1
- data/test/section_test.rb +53 -0
- metadata +32 -7
- data/test/ror_vs_wild_test.rb +0 -147
data/test/run.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/helper")
|
2
|
+
|
3
|
+
class RorVsWild::SectionTest < Minitest::Test
|
4
|
+
include RorVsWildAgentHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
agent
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_sibling?
|
11
|
+
refute(section1.sibling?(section2))
|
12
|
+
refute(section2.sibling?(section1))
|
13
|
+
|
14
|
+
section2.line = section1.line
|
15
|
+
assert(section1.sibling?(section2))
|
16
|
+
assert(section2.sibling?(section1))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_merge
|
20
|
+
section1.merge(section2)
|
21
|
+
assert_equal(3, section1.calls)
|
22
|
+
assert_equal(3, section1.total_runtime)
|
23
|
+
assert_equal(3, section1.children_runtime)
|
24
|
+
end
|
25
|
+
|
26
|
+
def section1
|
27
|
+
unless @section1
|
28
|
+
s = RorVsWild::Section.new
|
29
|
+
s.kind = "test"
|
30
|
+
s.file = "file"
|
31
|
+
s.line = 1
|
32
|
+
s.calls = 1
|
33
|
+
s.total_runtime = 1
|
34
|
+
s.children_runtime = 1
|
35
|
+
@section1 = s
|
36
|
+
end
|
37
|
+
@section1
|
38
|
+
end
|
39
|
+
|
40
|
+
def section2
|
41
|
+
unless @section2
|
42
|
+
s = RorVsWild::Section.new
|
43
|
+
s.kind = "test"
|
44
|
+
s.file = "file"
|
45
|
+
s.line = 2
|
46
|
+
s.calls = 2
|
47
|
+
s.total_runtime = 2
|
48
|
+
s.children_runtime = 2
|
49
|
+
@section2 = s
|
50
|
+
end
|
51
|
+
@section2
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rorvswild
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.pre.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Bernard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -40,23 +40,40 @@ files:
|
|
40
40
|
- bin/rorvswild-install
|
41
41
|
- cacert.pem
|
42
42
|
- lib/rorvswild.rb
|
43
|
+
- lib/rorvswild/agent.rb
|
43
44
|
- lib/rorvswild/client.rb
|
44
45
|
- lib/rorvswild/installer.rb
|
45
46
|
- lib/rorvswild/location.rb
|
47
|
+
- lib/rorvswild/plugin/action_controller.rb
|
48
|
+
- lib/rorvswild/plugin/action_mailer.rb
|
49
|
+
- lib/rorvswild/plugin/action_view.rb
|
50
|
+
- lib/rorvswild/plugin/active_job.rb
|
51
|
+
- lib/rorvswild/plugin/active_record.rb
|
52
|
+
- lib/rorvswild/plugin/delayed_job.rb
|
46
53
|
- lib/rorvswild/plugin/mongo.rb
|
47
54
|
- lib/rorvswild/plugin/net_http.rb
|
48
55
|
- lib/rorvswild/plugin/redis.rb
|
49
56
|
- lib/rorvswild/plugin/resque.rb
|
50
57
|
- lib/rorvswild/plugin/sidekiq.rb
|
58
|
+
- lib/rorvswild/plugins.rb
|
51
59
|
- lib/rorvswild/rails_loader.rb
|
60
|
+
- lib/rorvswild/section.rb
|
52
61
|
- lib/rorvswild/version.rb
|
53
62
|
- rorvswild.gemspec
|
54
63
|
- test/helper.rb
|
64
|
+
- test/measure_nested_sections_test.rb
|
65
|
+
- test/plugin/action_controller_test.rb
|
66
|
+
- test/plugin/action_mailer_test.rb
|
67
|
+
- test/plugin/action_view_test.rb
|
68
|
+
- test/plugin/active_job_test.rb
|
69
|
+
- test/plugin/active_record_test.rb
|
70
|
+
- test/plugin/delayed_job_test.rb
|
55
71
|
- test/plugin/mongo_test.rb
|
56
72
|
- test/plugin/net_http_test.rb
|
57
73
|
- test/plugin/redis_test.rb
|
58
|
-
- test/
|
74
|
+
- test/rorvswild_test.rb
|
59
75
|
- test/run.rb
|
76
|
+
- test/section_test.rb
|
60
77
|
homepage: https://www.rorvswild.com
|
61
78
|
licenses:
|
62
79
|
- MIT
|
@@ -72,20 +89,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
89
|
version: '0'
|
73
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
91
|
requirements:
|
75
|
-
- - "
|
92
|
+
- - ">"
|
76
93
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
94
|
+
version: 1.3.1
|
78
95
|
requirements: []
|
79
96
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.4.8
|
81
98
|
signing_key:
|
82
99
|
specification_version: 4
|
83
100
|
summary: Ruby on Rails app monitoring
|
84
101
|
test_files:
|
85
102
|
- test/helper.rb
|
103
|
+
- test/measure_nested_sections_test.rb
|
104
|
+
- test/plugin/action_controller_test.rb
|
105
|
+
- test/plugin/action_mailer_test.rb
|
106
|
+
- test/plugin/action_view_test.rb
|
107
|
+
- test/plugin/active_job_test.rb
|
108
|
+
- test/plugin/active_record_test.rb
|
109
|
+
- test/plugin/delayed_job_test.rb
|
86
110
|
- test/plugin/mongo_test.rb
|
87
111
|
- test/plugin/net_http_test.rb
|
88
112
|
- test/plugin/redis_test.rb
|
89
|
-
- test/
|
113
|
+
- test/rorvswild_test.rb
|
90
114
|
- test/run.rb
|
115
|
+
- test/section_test.rb
|
91
116
|
has_rdoc:
|
data/test/ror_vs_wild_test.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/helper")
|
2
|
-
|
3
|
-
class RorVsWildTest < Minitest::Test
|
4
|
-
include TopTests
|
5
|
-
|
6
|
-
def test_measure_code
|
7
|
-
client.expects(:post_job)
|
8
|
-
assert_equal(2, client.measure_code("1 + 1"))
|
9
|
-
assert_equal("1 + 1", client.send(:job)[:name])
|
10
|
-
assert(client.send(:job)[:runtime] > 0)
|
11
|
-
assert_equal(0, client.send(:job)[:cpu_runtime])
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_measure_code_when_raising
|
15
|
-
client.expects(:post_job)
|
16
|
-
assert_raises(RuntimeError) { client.measure_code("raise 'error'") }
|
17
|
-
assert_equal(("raise 'error'"), client.send(:job)[:name])
|
18
|
-
assert(client.send(:job)[:cpu_runtime])
|
19
|
-
assert(client.send(:job)[:runtime])
|
20
|
-
assert(client.send(:job)[:error])
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_mesure_block_when_exception_is_ignored
|
24
|
-
client = initialize_client(ignored_exceptions: %w[ZeroDivisionError])
|
25
|
-
client.expects(:post_job)
|
26
|
-
assert_raises(ZeroDivisionError) { RorVsWild.measure_code("1/0") }
|
27
|
-
refute(client.send(:job)[:error])
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_measure_code_when_no_client
|
31
|
-
RorVsWild.register_client(nil)
|
32
|
-
RorVsWild::Client.any_instance.expects(:post_job).never
|
33
|
-
assert_equal(2, RorVsWild.measure_code("1+1"))
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_measure_block_when_no_client
|
37
|
-
RorVsWild.register_client(nil)
|
38
|
-
RorVsWild::Client.any_instance.expects(:post_job).never
|
39
|
-
assert_equal(2, RorVsWild.measure_block("1+1") { 1+1 })
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_measure_block_recursive
|
43
|
-
client.expects(:post_job)
|
44
|
-
result = RorVsWild.measure_block("1") do
|
45
|
-
RorVsWild.measure_block("2") { 1 } + 1
|
46
|
-
end
|
47
|
-
assert_equal(2, result)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_catch_error
|
51
|
-
client.expects(:post_error)
|
52
|
-
exception = RorVsWild.catch_error { 1 / 0 }
|
53
|
-
assert_equal(ZeroDivisionError, exception.class)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_catch_error_with_extra_details
|
57
|
-
client.expects(:post_error)
|
58
|
-
exception = RorVsWild.catch_error(foo: "bar") { 1 / 0 }
|
59
|
-
assert_equal(ZeroDivisionError, exception.class)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_catch_error_when_no_errors
|
63
|
-
client.expects(:post_error).never
|
64
|
-
assert_equal(2, RorVsWild.catch_error { 1 + 1 })
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_extract_most_relevant_location
|
68
|
-
callstack = ["#{ENV["GEM_HOME"]}/lib/sql.rb:1:in `method1'", "/usr/lib/ruby/net/http.rb:2:in `method2'", "/rails/root/app/models/user.rb:3:in `method3'"]
|
69
|
-
assert_equal(%w[/app/models/user.rb 3 method3], client.extract_most_relevant_location(callstack))
|
70
|
-
|
71
|
-
assert_equal(["#{ENV["GEM_HOME"]}/lib/sql.rb", "1", "method1"], client.extract_most_relevant_location(["#{ENV["GEM_HOME"]}/lib/sql.rb:1:in `method1'"]))
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_extract_most_relevant_location_when_there_is_not_app_root
|
75
|
-
client = initialize_client
|
76
|
-
callstack = ["#{ENV["GEM_HOME"]}/lib/sql.rb:1:in `method1'", "/usr/lib/ruby/net/http.rb:2:in `method2'", "/rails/root/app/models/user.rb:3:in `method3'"]
|
77
|
-
assert_equal(%w[/usr/lib/ruby/net/http.rb 2 method2], client.extract_most_relevant_location(callstack))
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_extract_most_relevant_location_when_there_is_no_method_name
|
81
|
-
assert_equal(["/foo/bar.rb", "123", nil], client.extract_most_relevant_location(["/foo/bar.rb:123"]))
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_extract_most_relevant_location_when_gem_home_is_in_heroku_app_root
|
85
|
-
client = initialize_client(app_root: app_root = File.dirname(gem_home = ENV["GEM_HOME"]))
|
86
|
-
callstack = ["#{gem_home}/lib/sql.rb:1:in `method1'", "/usr/lib/ruby/net/http.rb:2:in `method2'", "#{app_root}/app/models/user.rb:3:in `method3'"]
|
87
|
-
assert_equal(["/app/models/user.rb", "3", "method3"], client.extract_most_relevant_location(callstack))
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_extract_most_relevant_location_when_gem_path_is_set_instead_of_gem_home
|
91
|
-
original_gem_home, original_gem_path = ENV["GEM_HOME"], ENV["GEM_PATH"]
|
92
|
-
ENV["GEM_HOME"], ENV["GEM_PATH"] = "", "/gem/path"
|
93
|
-
|
94
|
-
callstack = ["/gem/path/lib/sql.rb:1:in `method1'", "/usr/lib/ruby/net/http.rb:2:in `method2'", "/rails/root/app/models/user.rb:3:in `method3'"]
|
95
|
-
assert_equal(%w[/app/models/user.rb 3 method3], client.extract_most_relevant_location(callstack))
|
96
|
-
ensure
|
97
|
-
ENV["GEM_HOME"], ENV["GEM_PATH"] = original_gem_home, original_gem_path
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_extract_most_relevant_location_when_gem_path_and_gem_home_are_undefined
|
101
|
-
original_gem_home, original_gem_path = ENV["GEM_HOME"], ENV["GEM_PATH"]
|
102
|
-
ENV["GEM_HOME"], ENV["GEM_PATH"] = "", ""
|
103
|
-
|
104
|
-
callstack = ["/gem/path/lib/sql.rb:1:in `method1'", "/usr/lib/ruby/net/http.rb:2:in `method2'", "/rails/root/app/models/user.rb:3:in `method3'"]
|
105
|
-
assert_equal(%w[/app/models/user.rb 3 method3], client.extract_most_relevant_location(callstack))
|
106
|
-
ensure
|
107
|
-
ENV["GEM_HOME"], ENV["GEM_PATH"] = original_gem_home, original_gem_path
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_push_query
|
111
|
-
client = initialize_client
|
112
|
-
client.send(:data)[:queries] = []
|
113
|
-
client.send(:push_query, {kind: "sql", file: "file", line: 123, command: "BEGIN", runtime: 10})
|
114
|
-
client.send(:push_query, {kind: "sql", file: "file", line: 123, command: "SELECT 1", runtime: 10})
|
115
|
-
client.send(:push_query, {kind: "sql", file: "file", line: 123, command: "SELECT 1", runtime: 10})
|
116
|
-
client.send(:push_query, {kind: "sql", file: "file", line: 123, command: "COMMIT", runtime: 10})
|
117
|
-
assert_equal([{kind: "sql", file: "file", line: 123, command: "SELECT 1", runtime: 40, times: 2}], client.send(:queries))
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_after_exception
|
121
|
-
exception, controller = nil, stub(session: {}, request: stub(env: ENV))
|
122
|
-
begin; 1/0; rescue => exception; end
|
123
|
-
assert_raises(ZeroDivisionError) { client.after_exception(exception, controller) }
|
124
|
-
assert_equal("ZeroDivisionError", client.send(:request)[:error][:exception])
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_after_exception_when_ignored
|
128
|
-
client = initialize_client(ignored_exceptions: %w[ZeroDivisionError])
|
129
|
-
exception, controller = nil, stub(session: {}, request: stub(env: ENV))
|
130
|
-
begin; raise 1/0; rescue => exception; end
|
131
|
-
assert_raises(ZeroDivisionError) { client.after_exception(exception, controller) }
|
132
|
-
refute(client.send(:request)[:error])
|
133
|
-
end
|
134
|
-
|
135
|
-
private
|
136
|
-
|
137
|
-
def client
|
138
|
-
@client ||= initialize_client(app_root: "/rails/root")
|
139
|
-
end
|
140
|
-
|
141
|
-
def initialize_client(options = {})
|
142
|
-
client ||= RorVsWild::Client.new(options)
|
143
|
-
client.stubs(:post_request)
|
144
|
-
client.stubs(:post_task)
|
145
|
-
client
|
146
|
-
end
|
147
|
-
end
|