oboe 2.7.0.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +51 -0
  4. data/Appraisals +10 -0
  5. data/CHANGELOG.md +223 -0
  6. data/Gemfile +49 -0
  7. data/LICENSE +199 -0
  8. data/README.md +380 -0
  9. data/Rakefile +106 -0
  10. data/ext/oboe_metal/extconf.rb +61 -0
  11. data/ext/oboe_metal/noop/noop.c +7 -0
  12. data/ext/oboe_metal/src/bson/bson.h +221 -0
  13. data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
  14. data/ext/oboe_metal/src/oboe.h +275 -0
  15. data/ext/oboe_metal/src/oboe.hpp +352 -0
  16. data/ext/oboe_metal/src/oboe_wrap.cxx +3886 -0
  17. data/ext/oboe_metal/tests/test.rb +11 -0
  18. data/gemfiles/mongo.gemfile +33 -0
  19. data/gemfiles/moped.gemfile +33 -0
  20. data/get_version.rb +5 -0
  21. data/init.rb +4 -0
  22. data/lib/base.rb +99 -0
  23. data/lib/joboe_metal.rb +185 -0
  24. data/lib/method_profiling.rb +70 -0
  25. data/lib/oboe.rb +50 -0
  26. data/lib/oboe/api.rb +14 -0
  27. data/lib/oboe/api/layerinit.rb +99 -0
  28. data/lib/oboe/api/logging.rb +129 -0
  29. data/lib/oboe/api/memcache.rb +29 -0
  30. data/lib/oboe/api/profiling.rb +50 -0
  31. data/lib/oboe/api/tracing.rb +134 -0
  32. data/lib/oboe/api/util.rb +117 -0
  33. data/lib/oboe/config.rb +140 -0
  34. data/lib/oboe/frameworks/grape.rb +74 -0
  35. data/lib/oboe/frameworks/padrino.rb +66 -0
  36. data/lib/oboe/frameworks/padrino/templates.rb +59 -0
  37. data/lib/oboe/frameworks/rails.rb +139 -0
  38. data/lib/oboe/frameworks/rails/helpers/rum/rum_ajax_header.js.erb +5 -0
  39. data/lib/oboe/frameworks/rails/helpers/rum/rum_footer.js.erb +1 -0
  40. data/lib/oboe/frameworks/rails/helpers/rum/rum_header.js.erb +3 -0
  41. data/lib/oboe/frameworks/rails/inst/action_controller.rb +123 -0
  42. data/lib/oboe/frameworks/rails/inst/action_view.rb +56 -0
  43. data/lib/oboe/frameworks/rails/inst/action_view_2x.rb +54 -0
  44. data/lib/oboe/frameworks/rails/inst/action_view_30.rb +48 -0
  45. data/lib/oboe/frameworks/rails/inst/active_record.rb +24 -0
  46. data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
  47. data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
  48. data/lib/oboe/frameworks/rails/inst/connection_adapters/oracle.rb +18 -0
  49. data/lib/oboe/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
  50. data/lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb +118 -0
  51. data/lib/oboe/frameworks/sinatra.rb +96 -0
  52. data/lib/oboe/frameworks/sinatra/templates.rb +56 -0
  53. data/lib/oboe/inst/cassandra.rb +281 -0
  54. data/lib/oboe/inst/dalli.rb +75 -0
  55. data/lib/oboe/inst/http.rb +72 -0
  56. data/lib/oboe/inst/memcache.rb +105 -0
  57. data/lib/oboe/inst/memcached.rb +96 -0
  58. data/lib/oboe/inst/mongo.rb +240 -0
  59. data/lib/oboe/inst/moped.rb +474 -0
  60. data/lib/oboe/inst/rack.rb +81 -0
  61. data/lib/oboe/inst/redis.rb +273 -0
  62. data/lib/oboe/inst/resque.rb +193 -0
  63. data/lib/oboe/instrumentation.rb +18 -0
  64. data/lib/oboe/loading.rb +98 -0
  65. data/lib/oboe/logger.rb +41 -0
  66. data/lib/oboe/ruby.rb +11 -0
  67. data/lib/oboe/util.rb +129 -0
  68. data/lib/oboe/version.rb +13 -0
  69. data/lib/oboe/xtrace.rb +52 -0
  70. data/lib/oboe_metal.rb +140 -0
  71. data/lib/rails/generators/oboe/install_generator.rb +76 -0
  72. data/lib/rails/generators/oboe/templates/oboe_initializer.rb +94 -0
  73. data/oboe.gemspec +29 -0
  74. data/release.sh +65 -0
  75. data/test/frameworks/apps/grape_simple.rb +10 -0
  76. data/test/frameworks/apps/padrino_simple.rb +41 -0
  77. data/test/frameworks/apps/sinatra_simple.rb +20 -0
  78. data/test/frameworks/grape_test.rb +27 -0
  79. data/test/frameworks/padrino_test.rb +25 -0
  80. data/test/frameworks/sinatra_test.rb +25 -0
  81. data/test/instrumentation/cassandra_test.rb +381 -0
  82. data/test/instrumentation/dalli_test.rb +164 -0
  83. data/test/instrumentation/http_test.rb +97 -0
  84. data/test/instrumentation/memcache_test.rb +251 -0
  85. data/test/instrumentation/memcached_test.rb +226 -0
  86. data/test/instrumentation/mongo_test.rb +462 -0
  87. data/test/instrumentation/moped_test.rb +473 -0
  88. data/test/instrumentation/rack_test.rb +73 -0
  89. data/test/instrumentation/redis_hashes_test.rb +265 -0
  90. data/test/instrumentation/redis_keys_test.rb +318 -0
  91. data/test/instrumentation/redis_lists_test.rb +310 -0
  92. data/test/instrumentation/redis_misc_test.rb +160 -0
  93. data/test/instrumentation/redis_sets_test.rb +293 -0
  94. data/test/instrumentation/redis_sortedsets_test.rb +325 -0
  95. data/test/instrumentation/redis_strings_test.rb +333 -0
  96. data/test/instrumentation/resque_test.rb +62 -0
  97. data/test/minitest_helper.rb +148 -0
  98. data/test/profiling/method_test.rb +198 -0
  99. data/test/support/config_test.rb +39 -0
  100. data/test/support/liboboe_settings_test.rb +46 -0
  101. data/test/support/xtrace_test.rb +35 -0
  102. metadata +200 -0
@@ -0,0 +1,333 @@
1
+ require 'minitest_helper'
2
+ require "redis"
3
+
4
+ describe Oboe::Inst::Redis, :strings do
5
+ attr_reader :entry_kvs, :exit_kvs, :redis, :redis_version
6
+
7
+ def min_server_version(version)
8
+ unless Gem::Version.new(@redis_version) >= Gem::Version.new(version.to_s)
9
+ skip "supported only on redis-server #{version} or greater"
10
+ end
11
+ end
12
+
13
+ before do
14
+ clear_all_traces
15
+
16
+ @redis ||= Redis.new
17
+
18
+ @redis_version ||= @redis.info["redis_version"]
19
+
20
+ # These are standard entry/exit KVs that are passed up with all moped operations
21
+ @entry_kvs ||= { 'Layer' => 'redis_test', 'Label' => 'entry' }
22
+ @exit_kvs ||= { 'Layer' => 'redis_test', 'Label' => 'exit' }
23
+ end
24
+
25
+ it "should trace append" do
26
+ @redis.set("yourkey", "test")
27
+
28
+ Oboe::API.start_trace('redis_test', '', {}) do
29
+ @redis.append("yourkey", "blah")
30
+ end
31
+
32
+ traces = get_all_traces
33
+ traces.count.must_equal 4
34
+ traces[2]['KVOp'].must_equal "append"
35
+ traces[2]['KVKey'].must_equal "yourkey"
36
+ end
37
+
38
+ it "should trace bitcount (>=2.6)" do
39
+
40
+ min_server_version("2.6")
41
+
42
+ Oboe::API.start_trace('redis_test', '', {}) do
43
+ @redis.bitcount("yourkey")
44
+ end
45
+
46
+ traces = get_all_traces
47
+ traces.count.must_equal 4
48
+ traces[2]['KVOp'].must_equal "bitcount"
49
+ traces[2]['start'].must_equal "0"
50
+ traces[2]['stop'].must_equal "-1"
51
+ end
52
+
53
+ it "should trace bitop (>=2.6)" do
54
+
55
+ min_server_version("2.6")
56
+
57
+ Oboe::API.start_trace('redis_test', '', {}) do
58
+ @redis.bitop("not", "bitopkey", "yourkey")
59
+ end
60
+
61
+ traces = get_all_traces
62
+ traces.count.must_equal 4
63
+ traces[2]['KVOp'].must_equal "bitop"
64
+ traces[2]['operation'].must_equal "not"
65
+ traces[2]['destkey'].must_equal "bitopkey"
66
+ end
67
+
68
+ it "should trace decr" do
69
+ @redis.setex("decr", 60, 0)
70
+
71
+ Oboe::API.start_trace('redis_test', '', {}) do
72
+ @redis.decr("decr")
73
+ end
74
+
75
+ traces = get_all_traces
76
+ traces.count.must_equal 4
77
+ traces[2]['KVOp'].must_equal "decr"
78
+ traces[2]['KVKey'].must_equal "decr"
79
+ end
80
+
81
+ it "should trace decrby" do
82
+ @redis.setex("decr", 60, 0)
83
+
84
+ Oboe::API.start_trace('redis_test', '', {}) do
85
+ @redis.decrby("decr", 1)
86
+ end
87
+
88
+ traces = get_all_traces
89
+ traces.count.must_equal 4
90
+ traces[2]['KVOp'].must_equal "decrby"
91
+ traces[2]['KVKey'].must_equal "decr"
92
+ traces[2]['decrement'].must_equal "1"
93
+ end
94
+
95
+ it "should trace get" do
96
+ @redis.setex("diwore", 60, "okokok")
97
+
98
+ Oboe::API.start_trace('redis_test', '', {}) do
99
+ @rv = @redis.get("diwore")
100
+ end
101
+
102
+ @rv.must_equal "okokok"
103
+
104
+ traces = get_all_traces
105
+ traces.count.must_equal 4
106
+ traces[2]['KVOp'].must_equal "get"
107
+ traces[2]['KVKey'].must_equal "diwore"
108
+ end
109
+
110
+ it "should trace getbit" do
111
+ min_server_version(2.2)
112
+
113
+ @redis.setex("diwore", 60, "okokok")
114
+
115
+ Oboe::API.start_trace('redis_test', '', {}) do
116
+ @redis.getbit("diwore", 3)
117
+ end
118
+
119
+ traces = get_all_traces
120
+ traces.count.must_equal 4
121
+ traces[2]['KVOp'].must_equal "getbit"
122
+ traces[2]['KVKey'].must_equal "diwore"
123
+ traces[2]['offset'].must_equal "3"
124
+ end
125
+
126
+ it "should trace getrange" do
127
+ min_server_version(2.2)
128
+
129
+ Oboe::API.start_trace('redis_test', '', {}) do
130
+ @redis.getrange("yourkey", 0, 3)
131
+ end
132
+
133
+ traces = get_all_traces
134
+ traces.count.must_equal 4
135
+ traces[2]['KVOp'].must_equal "getrange"
136
+ traces[2]['KVKey'].must_equal "yourkey"
137
+ traces[2]['start'].must_equal "0"
138
+ traces[2]['end'].must_equal "3"
139
+ end
140
+
141
+ it "should trace getset" do
142
+ min_server_version(2.2)
143
+
144
+ Oboe::API.start_trace('redis_test', '', {}) do
145
+ @redis.getset("dollar", 0)
146
+ end
147
+
148
+ traces = get_all_traces
149
+ traces.count.must_equal 4
150
+ traces[2]['KVOp'].must_equal "getset"
151
+ traces[2]['KVKey'].must_equal "dollar"
152
+ traces[2]['value'].must_equal "0"
153
+ end
154
+
155
+ it "should trace incr" do
156
+ @redis.setex("dotcom", 60, 0)
157
+
158
+ Oboe::API.start_trace('redis_test', '', {}) do
159
+ @redis.incr("dotcom")
160
+ end
161
+
162
+ traces = get_all_traces
163
+ traces.count.must_equal 4
164
+ traces[2]['KVOp'].must_equal "incr"
165
+ traces[2]['KVKey'].must_equal "dotcom"
166
+ end
167
+
168
+ it "should trace incrby" do
169
+ @redis.setex("incr", 60, 0)
170
+
171
+ Oboe::API.start_trace('redis_test', '', {}) do
172
+ @redis.incrby("incr", 1)
173
+ end
174
+
175
+ traces = get_all_traces
176
+ traces.count.must_equal 4
177
+ traces[2]['KVOp'].must_equal "incrby"
178
+ traces[2]['KVKey'].must_equal "incr"
179
+ traces[2]['increment'].must_equal "1"
180
+ end
181
+
182
+ it "should trace incrbyfloat" do
183
+ min_server_version(2.6)
184
+
185
+ @redis.setex("incrfloat", 60, 0.0)
186
+
187
+ Oboe::API.start_trace('redis_test', '', {}) do
188
+ @redis.incrbyfloat("incrfloat", 1.01)
189
+ end
190
+
191
+ traces = get_all_traces
192
+ traces.count.must_equal 4
193
+ traces[2]['KVOp'].must_equal "incrbyfloat"
194
+ traces[2]['KVKey'].must_equal "incrfloat"
195
+ traces[2]['increment'].must_equal "1.01"
196
+ end
197
+
198
+ it "should trace mget" do
199
+ @redis.setex("france", 60, "ok")
200
+ @redis.setex("denmark", 60, "ok")
201
+ @redis.setex("germany", 60, "ok")
202
+
203
+ Oboe::API.start_trace('redis_test', '', {}) do
204
+ @redis.mget(["france", "nothing", "denmark"])
205
+ @redis.mget("germany")
206
+ end
207
+
208
+ traces = get_all_traces
209
+ traces.count.must_equal 6
210
+ traces[2]['KVOp'].must_equal "mget"
211
+ traces[2]['KVKeyCount'].must_equal "3"
212
+ traces[2]['KVHitCount'].must_equal "2"
213
+ traces[4]['KVOp'].must_equal "mget"
214
+ traces[4]['KVKeyCount'].must_equal "1"
215
+ traces[4]['KVHitCount'].must_equal "1"
216
+ end
217
+
218
+ it "should trace mset" do
219
+ Oboe::API.start_trace('redis_test', '', {}) do
220
+ @redis.mset(["one", 1, "two", 2, "three", 3])
221
+ @redis.mset("one", 1)
222
+ end
223
+
224
+ traces = get_all_traces
225
+ traces.count.must_equal 6
226
+ traces[2]['KVOp'].must_equal "mset"
227
+ traces[2]['KVKeyCount'].must_equal "3"
228
+ traces[4]['KVOp'].must_equal "mset"
229
+ traces[4]['KVKeyCount'].must_equal "1"
230
+ end
231
+
232
+ it "should trace msetnx" do
233
+ Oboe::API.start_trace('redis_test', '', {}) do
234
+ @redis.msetnx(["one", 1, "two", 2, "three", 3])
235
+ end
236
+
237
+ traces = get_all_traces
238
+ traces.count.must_equal 4
239
+ traces[2]['KVOp'].must_equal "msetnx"
240
+ end
241
+
242
+ it "should trace psetex (>= v2.6)" do
243
+
244
+ Oboe::API.start_trace('redis_test', '', {}) do
245
+ @redis.psetex("one", 60, "hello")
246
+ end
247
+
248
+ traces = get_all_traces
249
+ traces.count.must_equal 4
250
+ traces[2]['KVOp'].must_equal "psetex"
251
+ traces[2]['KVKey'].must_equal "one"
252
+ traces[2]['ttl'].must_equal "60"
253
+ end
254
+
255
+ it "should trace basic set" do
256
+ Oboe::API.start_trace('redis_test', '', {}) do
257
+ @redis.set("one", "hello")
258
+ end
259
+
260
+ traces = get_all_traces
261
+ traces.count.must_equal 4
262
+ traces[2]['KVOp'].must_equal "set"
263
+ traces[2]['KVKey'].must_equal "one"
264
+ end
265
+
266
+ it "should trace setbit" do
267
+ min_server_version(2.2)
268
+
269
+ Oboe::API.start_trace('redis_test', '', {}) do
270
+ @redis.setbit("yourkey", 3, 0)
271
+ end
272
+
273
+ traces = get_all_traces
274
+ traces.count.must_equal 4
275
+ traces[2]['KVOp'].must_equal "setbit"
276
+ traces[2]['KVKey'].must_equal "yourkey"
277
+ traces[2]['offset'].must_equal "3"
278
+ end
279
+
280
+ it "should trace setex" do
281
+ Oboe::API.start_trace('redis_test', '', {}) do
282
+ @redis.setex("one", 60, "hello")
283
+ end
284
+
285
+ traces = get_all_traces
286
+ traces.count.must_equal 4
287
+ traces[2]['KVOp'].must_equal "setex"
288
+ traces[2]['KVKey'].must_equal "one"
289
+ traces[2]['ttl'].must_equal "60"
290
+ end
291
+
292
+ it "should trace setnx" do
293
+ Oboe::API.start_trace('redis_test', '', {}) do
294
+ @redis.setnx("one", "hello")
295
+ end
296
+
297
+ traces = get_all_traces
298
+ traces.count.must_equal 4
299
+ traces[2]['KVOp'].must_equal "setnx"
300
+ traces[2]['KVKey'].must_equal "one"
301
+ end
302
+
303
+ it "should trace setrange" do
304
+ min_server_version(2.2)
305
+
306
+ @redis.setex("spandau_ballet", 60, "XXXXXXXXXXXXXXX")
307
+
308
+ Oboe::API.start_trace('redis_test', '', {}) do
309
+ @redis.setrange("yourkey", 2, "ok")
310
+ end
311
+
312
+ traces = get_all_traces
313
+ traces.count.must_equal 4
314
+ traces[2]['KVOp'].must_equal "setrange"
315
+ traces[2]['KVKey'].must_equal "yourkey"
316
+ traces[2]['offset'].must_equal "2"
317
+ end
318
+
319
+ it "should trace strlen" do
320
+ min_server_version(2.2)
321
+
322
+ @redis.setex("talking_heads", 60, "burning down the house")
323
+
324
+ Oboe::API.start_trace('redis_test', '', {}) do
325
+ @redis.strlen("talking_heads")
326
+ end
327
+
328
+ traces = get_all_traces
329
+ traces.count.must_equal 4
330
+ traces[2]['KVOp'].must_equal "strlen"
331
+ traces[2]['KVKey'].must_equal "talking_heads"
332
+ end
333
+ end
@@ -0,0 +1,62 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Oboe::Inst::Resque do
4
+ before do
5
+ clear_all_traces
6
+
7
+ # These are standard entry/exit KVs that are passed up with all moped operations
8
+ @entry_kvs = {
9
+ 'Layer' => 'resque',
10
+ 'Label' => 'entry' }
11
+
12
+ @exit_kvs = { 'Layer' => 'resque', 'Label' => 'exit' }
13
+ end
14
+
15
+ it 'Stock Resque should be loaded, defined and ready' do
16
+ defined?(::Resque).wont_match nil
17
+ defined?(::Resque::Worker).wont_match nil
18
+ defined?(::Resque::Job).wont_match nil
19
+ end
20
+
21
+ it 'Resque should have oboe methods defined' do
22
+ [ :enqueue, :enqueue_to, :dequeue ].each do |m|
23
+ ::Resque.method_defined?("#{m}_with_oboe").must_equal true
24
+ end
25
+
26
+ ::Resque::Worker.method_defined?("perform_with_oboe").must_equal true
27
+ ::Resque::Job.method_defined?("fail_with_oboe").must_equal true
28
+ end
29
+
30
+ it "should trace enqueue" do
31
+ skip
32
+ Oboe::API.start_trace('resque-client_test', '', {}) do
33
+ Resque.enqueue(OboeResqueJob, { :generate => :activerecord, :delay => rand(5..30).to_f })
34
+ Resque.enqueue(OboeResqueJobThatFails)
35
+ Resque.dequeue(OboeResqueJob, { :generate => :moped })
36
+ end
37
+
38
+ traces = get_all_traces
39
+
40
+ traces.count.must_equal 4
41
+ validate_outer_layers(traces, 'resque-client_test')
42
+
43
+ validate_event_keys(traces[1], @entry_kvs)
44
+ validate_event_keys(traces[2], @exit_kvs)
45
+ end
46
+
47
+ it "should trace dequeue" do
48
+ skip
49
+ Oboe::API.start_trace('resque-client_test', '', {}) do
50
+ Resque.dequeue(OboeResqueJob, { :generate => :moped })
51
+ end
52
+
53
+ traces = get_all_traces
54
+
55
+ traces.count.must_equal 4
56
+ validate_outer_layers(traces, 'resque-client_test')
57
+
58
+ validate_event_keys(traces[1], @entry_kvs)
59
+ validate_event_keys(traces[2], @exit_kvs)
60
+ end
61
+ end
62
+
@@ -0,0 +1,148 @@
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+ require "minitest/reporters"
4
+
5
+ ENV["RACK_ENV"] = "test"
6
+ ENV["OBOE_GEM_TEST"] = "true"
7
+
8
+ # FIXME: Temp hack to fix padrino-core calling RUBY_ENGINE when it's
9
+ # not defined under Ruby 1.8.7 and 1.9.3
10
+ RUBY_ENGINE = "ruby" unless defined?(RUBY_ENGINE)
11
+
12
+ Minitest::Spec.new 'pry'
13
+
14
+ unless RUBY_VERSION =~ /^1.8/
15
+ MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
16
+ end
17
+
18
+ if defined?(JRUBY_VERSION)
19
+ ENV['JAVA_OPTS'] = "-J-javaagent:/usr/local/tracelytics/tracelyticsagent.jar"
20
+ end
21
+
22
+ require 'rubygems'
23
+ require 'bundler'
24
+
25
+ # Preload memcache-client
26
+ require 'memcache'
27
+
28
+ Bundler.require(:default, :test)
29
+
30
+ @trace_dir = "/tmp/"
31
+ $trace_file = @trace_dir + "trace_output.bson"
32
+
33
+ # Configure Oboe
34
+ Oboe::Config[:verbose] = true
35
+ Oboe::Config[:tracing_mode] = "always"
36
+ Oboe::Config[:sample_rate] = 1000000
37
+ Oboe::Ruby.initialize
38
+ Oboe.logger.level = Logger::DEBUG
39
+
40
+ ##
41
+ # clear_all_traces
42
+ #
43
+ # Truncates the trace output file to zero
44
+ #
45
+ def clear_all_traces
46
+ Oboe::Reporter.clear_all_traces
47
+ end
48
+
49
+ ##
50
+ # get_all_traces
51
+ #
52
+ # Retrieves all traces written to the trace file
53
+ #
54
+ def get_all_traces
55
+ Oboe::Reporter.get_all_traces
56
+ end
57
+
58
+ ##
59
+ # validate_outer_layers
60
+ #
61
+ # Validates that the KVs in kvs are present
62
+ # in event
63
+ #
64
+ def validate_outer_layers(traces, layer)
65
+ traces.first['Layer'].must_equal layer
66
+ traces.first['Label'].must_equal 'entry'
67
+ traces.last['Layer'].must_equal layer
68
+ traces.last['Label'].must_equal 'exit'
69
+ end
70
+
71
+ ##
72
+ # validate_event_keys
73
+ #
74
+ # Validates that the KVs in kvs are present
75
+ # in event
76
+ #
77
+ def validate_event_keys(event, kvs)
78
+ kvs.each do |k, v|
79
+ event.has_key?(k).must_equal true
80
+ event[k].must_equal v
81
+ end
82
+ end
83
+
84
+ ##
85
+ # layer_has_key
86
+ #
87
+ # Checks an array of trace events if a specific layer (regardless of event type)
88
+ # has he specified key
89
+ #
90
+ def layer_has_key(traces, layer, key)
91
+ return false if traces.empty?
92
+ has_key = false
93
+
94
+ traces.each do |t|
95
+ if t["Layer"] == layer and t.has_key?(key)
96
+ has_key = true
97
+
98
+ (t["Backtrace"].length > 0).must_equal true
99
+ end
100
+ end
101
+
102
+ has_key.must_equal true
103
+ end
104
+
105
+ ##
106
+ # layer_doesnt_have_key
107
+ #
108
+ # Checks an array of trace events to assure that a specific layer
109
+ # (regardless of event type) doesn't have the specified key
110
+ #
111
+ def layer_doesnt_have_key(traces, layer, key)
112
+ return false if traces.empty?
113
+ has_key = false
114
+
115
+ traces.each do |t|
116
+ has_key = true if t["Layer"] == layer and t.has_key?(key)
117
+ end
118
+
119
+ has_key.must_equal false
120
+ end
121
+
122
+ ##
123
+ # Sinatra and Padrino Related Helpers
124
+ #
125
+ # Taken from padrino-core gem
126
+ #
127
+
128
+ class Sinatra::Base
129
+ # Allow assertions in request context
130
+ include MiniTest::Assertions
131
+ end
132
+
133
+
134
+ class MiniTest::Spec
135
+ include Rack::Test::Methods
136
+
137
+ # Sets up a Sinatra::Base subclass defined with the block
138
+ # given. Used in setup or individual spec methods to establish
139
+ # the application.
140
+ def mock_app(base=Padrino::Application, &block)
141
+ @app = Sinatra.new(base, &block)
142
+ end
143
+
144
+ def app
145
+ Rack::Lint.new(@app)
146
+ end
147
+ end
148
+