appsignal 2.11.10-java → 3.0.0.beta.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -1
  3. data/.semaphore/semaphore.yml +161 -70
  4. data/CHANGELOG.md +5 -18
  5. data/Rakefile +3 -13
  6. data/appsignal.gemspec +2 -24
  7. data/build_matrix.yml +20 -22
  8. data/gemfiles/capistrano2.gemfile +1 -0
  9. data/gemfiles/capistrano3.gemfile +1 -0
  10. data/gemfiles/grape.gemfile +1 -0
  11. data/gemfiles/no_dependencies.gemfile +1 -4
  12. data/gemfiles/rails-3.2.gemfile +0 -2
  13. data/gemfiles/rails-4.2.gemfile +0 -6
  14. data/gemfiles/resque-2.gemfile +4 -0
  15. data/gemfiles/sequel-435.gemfile +1 -0
  16. data/gemfiles/sequel.gemfile +1 -0
  17. data/gemfiles/sinatra.gemfile +1 -0
  18. data/lib/appsignal/auth_check.rb +2 -8
  19. data/lib/appsignal/cli.rb +1 -23
  20. data/lib/appsignal/config.rb +0 -24
  21. data/lib/appsignal/event_formatter.rb +0 -25
  22. data/lib/appsignal/extension.rb +0 -50
  23. data/lib/appsignal/hooks/action_cable.rb +5 -44
  24. data/lib/appsignal/hooks/active_support_notifications.rb +7 -86
  25. data/lib/appsignal/hooks/celluloid.rb +5 -9
  26. data/lib/appsignal/hooks/net_http.rb +2 -12
  27. data/lib/appsignal/hooks/puma.rb +3 -5
  28. data/lib/appsignal/hooks/que.rb +1 -1
  29. data/lib/appsignal/hooks/rake.rb +2 -24
  30. data/lib/appsignal/hooks/redis.rb +2 -13
  31. data/lib/appsignal/hooks/resque.rb +2 -43
  32. data/lib/appsignal/hooks/sidekiq.rb +1 -5
  33. data/lib/appsignal/hooks/unicorn.rb +3 -24
  34. data/lib/appsignal/hooks/webmachine.rb +1 -7
  35. data/lib/appsignal/hooks.rb +0 -23
  36. data/lib/appsignal/integrations/action_cable.rb +34 -0
  37. data/lib/appsignal/integrations/active_support_notifications.rb +77 -0
  38. data/lib/appsignal/integrations/net_http.rb +16 -0
  39. data/lib/appsignal/integrations/object.rb +61 -4
  40. data/lib/appsignal/integrations/padrino.rb +5 -7
  41. data/lib/appsignal/integrations/que.rb +26 -33
  42. data/lib/appsignal/integrations/railtie.rb +1 -4
  43. data/lib/appsignal/integrations/rake.rb +26 -2
  44. data/lib/appsignal/integrations/redis.rb +17 -0
  45. data/lib/appsignal/integrations/resque.rb +39 -10
  46. data/lib/appsignal/integrations/unicorn.rb +28 -0
  47. data/lib/appsignal/integrations/webmachine.rb +22 -24
  48. data/lib/appsignal/minutely.rb +0 -18
  49. data/lib/appsignal/transaction.rb +1 -1
  50. data/lib/appsignal/version.rb +1 -1
  51. data/lib/appsignal.rb +1 -27
  52. data/spec/lib/appsignal/auth_check_spec.rb +1 -24
  53. data/spec/lib/appsignal/cli_spec.rb +1 -1
  54. data/spec/lib/appsignal/config_spec.rb +0 -66
  55. data/spec/lib/appsignal/event_formatter_spec.rb +0 -37
  56. data/spec/lib/appsignal/extension_install_failure_spec.rb +7 -0
  57. data/spec/lib/appsignal/extension_spec.rb +9 -43
  58. data/spec/lib/appsignal/hooks/action_cable_spec.rb +0 -88
  59. data/spec/lib/appsignal/hooks/celluloid_spec.rb +6 -1
  60. data/spec/lib/appsignal/hooks/rake_spec.rb +1 -2
  61. data/spec/lib/appsignal/hooks/redis_spec.rb +50 -15
  62. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +7 -61
  63. data/spec/lib/appsignal/hooks/unicorn_spec.rb +14 -3
  64. data/spec/lib/appsignal/hooks/webmachine_spec.rb +2 -13
  65. data/spec/lib/appsignal/hooks_spec.rb +0 -57
  66. data/spec/lib/appsignal/integrations/object_spec.rb +4 -95
  67. data/spec/lib/appsignal/integrations/padrino_spec.rb +2 -3
  68. data/spec/lib/appsignal/integrations/railtie_spec.rb +0 -45
  69. data/spec/lib/appsignal/integrations/webmachine_spec.rb +26 -8
  70. data/spec/lib/appsignal/minutely_spec.rb +0 -19
  71. data/spec/lib/appsignal/transaction_spec.rb +1 -31
  72. data/spec/lib/appsignal/transmitter_spec.rb +1 -1
  73. data/spec/lib/appsignal/utils/data_spec.rb +87 -133
  74. data/spec/lib/appsignal_spec.rb +0 -69
  75. data/spec/lib/puma/appsignal_spec.rb +0 -28
  76. data/spec/spec_helper.rb +1 -37
  77. data/spec/support/testing.rb +1 -11
  78. data/support/install_deps +0 -4
  79. metadata +10 -23
  80. data/lib/appsignal/cli/notify_of_deploy.rb +0 -131
  81. data/lib/appsignal/integrations/object_ruby_19.rb +0 -37
  82. data/lib/appsignal/integrations/object_ruby_modern.rb +0 -41
  83. data/lib/appsignal/integrations/resque_active_job.rb +0 -19
  84. data/lib/appsignal/js_exception_transaction.rb +0 -56
  85. data/lib/appsignal/rack/js_exception_catcher.rb +0 -80
  86. data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +0 -180
  87. data/spec/lib/appsignal/integrations/object_19_spec.rb +0 -266
  88. data/spec/lib/appsignal/integrations/resque_active_job_spec.rb +0 -28
  89. data/spec/lib/appsignal/integrations/resque_spec.rb +0 -28
  90. data/spec/lib/appsignal/js_exception_transaction_spec.rb +0 -128
  91. data/spec/lib/appsignal/rack/js_exception_catcher_spec.rb +0 -170
@@ -3,8 +3,6 @@
3
3
  module Appsignal
4
4
  class Minutely
5
5
  class ProbeCollection
6
- include Appsignal::Utils::DeprecationMessage
7
-
8
6
  def initialize
9
7
  @probes = {}
10
8
  end
@@ -27,16 +25,6 @@ module Appsignal
27
25
  probes[key]
28
26
  end
29
27
 
30
- # @param probe [Object] Any object that listens to the `call` method will
31
- # be used as a probe.
32
- # @deprecated Use {#register} instead.
33
- # @return [void]
34
- def <<(probe)
35
- deprecation_message "Deprecated `Appsignal::Minute.probes <<` " \
36
- "call. Please use `Appsignal::Minutely.probes.register` instead."
37
- register probe.object_id, probe
38
- end
39
-
40
28
  # Register a new minutely probe.
41
29
  #
42
30
  # Supported probe types are:
@@ -135,12 +123,6 @@ module Appsignal
135
123
  def start
136
124
  stop
137
125
  @thread = Thread.new do
138
- # Advise multi-threaded app servers to ignore this thread
139
- # for the purposes of fork safety warnings
140
- if Thread.current.respond_to?(:thread_variable_set)
141
- Thread.current.thread_variable_set(:fork_safe, true)
142
- end
143
-
144
126
  sleep initial_wait_time
145
127
  initialize_probes
146
128
  loop do
@@ -90,7 +90,7 @@ module Appsignal
90
90
  @transaction_id,
91
91
  @namespace,
92
92
  self.class.garbage_collection_profiler.total_time
93
- ) || Appsignal::Extension::MockTransaction.new
93
+ )
94
94
  end
95
95
 
96
96
  def nil_transaction?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appsignal
4
- VERSION = "2.11.10".freeze
4
+ VERSION = "3.0.0.beta.1".freeze
5
5
  end
data/lib/appsignal.rb CHANGED
@@ -129,7 +129,6 @@ module Appsignal
129
129
  config.write_to_environment
130
130
  Appsignal::Extension.start
131
131
  Appsignal::Hooks.load_hooks
132
- Appsignal::EventFormatter.initialize_deprecated_formatters
133
132
  initialize_extensions
134
133
 
135
134
  if config[:enable_allocation_tracking] && !Appsignal::System.jruby?
@@ -222,15 +221,9 @@ module Appsignal
222
221
  # Sets the log level and sets the logger. Uses a file-based logger or the
223
222
  # STDOUT-based logger. See the `:log` configuration option.
224
223
  #
225
- # @param path_arg [nil] Deprecated param. Use the `:log_path`
226
- # configuration option instead.
227
224
  # @return [void]
228
225
  # @since 0.7.0
229
- def start_logger(path_arg = nil)
230
- if path_arg
231
- logger.info("Setting the path in start_logger has no effect anymore, set it in the config instead")
232
- end
233
-
226
+ def start_logger
234
227
  if config && config[:log] == "file" && config.log_file_path
235
228
  start_file_logger(config.log_file_path)
236
229
  else
@@ -285,21 +278,6 @@ module Appsignal
285
278
  config && config.active? && extension_loaded?
286
279
  end
287
280
 
288
- # @deprecated No replacement
289
- def is_ignored_error?(error) # rubocop:disable Naming/PredicateName
290
- deprecation_message "Appsignal.is_ignored_error? is deprecated " \
291
- "with no replacement and will be removed in version 3.0."
292
- Appsignal.config[:ignore_errors].include?(error.class.name)
293
- end
294
- alias :is_ignored_exception? :is_ignored_error?
295
-
296
- # @deprecated No replacement
297
- def is_ignored_action?(action) # rubocop:disable Naming/PredicateName
298
- deprecation_message "Appsignal.is_ignored_action? is deprecated " \
299
- "with no replacement and will be removed in version 3.0."
300
- Appsignal.config[:ignore_actions].include?(action)
301
- end
302
-
303
281
  private
304
282
 
305
283
  def start_stdout_logger
@@ -344,11 +322,7 @@ require "appsignal/marker"
344
322
  require "appsignal/minutely"
345
323
  require "appsignal/garbage_collection_profiler"
346
324
  require "appsignal/integrations/railtie" if defined?(::Rails)
347
- require "appsignal/integrations/resque"
348
- require "appsignal/integrations/resque_active_job"
349
325
  require "appsignal/transaction"
350
326
  require "appsignal/version"
351
327
  require "appsignal/rack/generic_instrumentation"
352
- require "appsignal/rack/js_exception_catcher"
353
- require "appsignal/js_exception_transaction"
354
328
  require "appsignal/transmitter"
@@ -28,29 +28,6 @@ describe Appsignal::AuthCheck do
28
28
  end.join("&")
29
29
  end
30
30
 
31
- describe ".new" do
32
- describe "with logger argument" do
33
- let(:err_stream) { std_stream }
34
- let(:stderr) { err_stream.read }
35
- let(:log_stream) { std_stream }
36
- let(:log) { log_contents(log_stream) }
37
-
38
- it "logs and prints a deprecation message" do
39
- Appsignal.logger = test_logger(log_stream)
40
-
41
- capture_std_streams(std_stream, err_stream) do
42
- Appsignal::AuthCheck.new(config, Appsignal.logger)
43
- end
44
-
45
- deprecation_message =
46
- "`Appsignal::AuthCheck.new`'s `logger` argument " \
47
- "will be removed in the next major version."
48
- expect(stderr).to include "appsignal WARNING: #{deprecation_message}"
49
- expect(log).to contains_log :warn, deprecation_message
50
- end
51
- end
52
- end
53
-
54
31
  describe "#perform" do
55
32
  subject { auth_check.perform }
56
33
 
@@ -62,7 +39,7 @@ describe Appsignal::AuthCheck do
62
39
  end
63
40
  end
64
41
 
65
- context "when encountering an exception", :not_ruby19 do
42
+ context "when encountering an exception" do
66
43
  before { stubbed_request.to_timeout }
67
44
 
68
45
  it "raises an error" do
@@ -16,7 +16,7 @@ describe Appsignal::CLI do
16
16
 
17
17
  expect(output).to include "appsignal <command> [options]"
18
18
  expect(output).to include \
19
- "Available commands: demo, diagnose, install, notify_of_deploy"
19
+ "Available commands: demo, diagnose, install"
20
20
  end
21
21
  end
22
22
 
@@ -168,8 +168,6 @@ describe Appsignal::Config do
168
168
  :push_api_key => "abc",
169
169
  :name => "TestApp",
170
170
  :active => true,
171
- :enable_frontend_error_catching => false,
172
- :frontend_error_catching_path => "/appsignal_error_catcher",
173
171
  :enable_allocation_tracking => true,
174
172
  :enable_gc_instrumentation => false,
175
173
  :enable_host_metrics => true,
@@ -357,70 +355,6 @@ describe Appsignal::Config do
357
355
  config
358
356
  end
359
357
  end
360
-
361
- describe "support for old config keys" do
362
- let(:err_stream) { std_stream }
363
- let(:stderr) { err_stream.read }
364
- let(:config) { project_fixture_config(env, {}, test_logger(log)) }
365
- let(:log) { StringIO.new }
366
- before { capture_std_streams(std_stream, err_stream) { config } }
367
-
368
- describe ":api_key" do
369
- context "without :push_api_key" do
370
- let(:env) { "old_config" }
371
-
372
- it "sets the :push_api_key with the old :api_key value" do
373
- expect(config[:push_api_key]).to eq "def"
374
- expect(config.config_hash).to_not have_key :api_key
375
-
376
- message = "Old configuration key found. Please update the 'api_key' to 'push_api_key'"
377
- expect(stderr).to include "appsignal WARNING: #{message}"
378
- expect(log_contents(log)).to contains_log :warn, message
379
- end
380
- end
381
-
382
- context "with :push_api_key" do
383
- let(:env) { "old_config_mixed_with_new_config" }
384
-
385
- it "ignores the :api_key config and deletes it" do
386
- expect(config[:push_api_key]).to eq "ghi"
387
- expect(config.config_hash).to_not have_key :api_key
388
-
389
- message = "Old configuration key found. Please update the 'api_key' to 'push_api_key'"
390
- expect(stderr).to include "appsignal WARNING: #{message}"
391
- expect(log_contents(log)).to contains_log :warn, message
392
- end
393
- end
394
- end
395
-
396
- describe ":ignore_exceptions" do
397
- context "without :ignore_errors" do
398
- let(:env) { "old_config" }
399
-
400
- it "sets :ignore_errors with the old :ignore_exceptions value" do
401
- expect(config[:ignore_errors]).to eq ["StandardError"]
402
- expect(config.config_hash).to_not have_key :ignore_exceptions
403
-
404
- message = "Old configuration key found. Please update the 'ignore_exceptions' to 'ignore_errors'"
405
- expect(stderr).to include "appsignal WARNING: #{message}"
406
- expect(log_contents(log)).to contains_log :warn, message
407
- end
408
- end
409
-
410
- context "with :ignore_errors" do
411
- let(:env) { "old_config_mixed_with_new_config" }
412
-
413
- it "ignores the :ignore_exceptions config" do
414
- expect(config[:ignore_errors]).to eq ["NoMethodError"]
415
- expect(config.config_hash).to_not have_key :ignore_exceptions
416
-
417
- message = "Old configuration key found. Please update the 'ignore_exceptions' to 'ignore_errors'"
418
- expect(stderr).to include "appsignal WARNING: #{message}"
419
- expect(log_contents(log)).to contains_log :warn, message
420
- end
421
- end
422
- end
423
- end
424
358
  end
425
359
 
426
360
  context "with config in the environment" do
@@ -114,43 +114,6 @@ describe Appsignal::EventFormatter do
114
114
  end
115
115
  end
116
116
  end
117
-
118
- context "when registering deprecated formatters" do
119
- let(:err_stream) { std_stream }
120
- let(:stderr) { err_stream.read }
121
- let(:deprecated_formatter) do
122
- Class.new(Appsignal::EventFormatter) do
123
- register "mock.deprecated"
124
-
125
- def format(_payload)
126
- end
127
- end
128
- end
129
-
130
- it "registers deprecated formatters and logs & prints a warning" do
131
- message = "Formatter for 'mock.deprecated' is using a deprecated registration method. " \
132
- "This event formatter will not be loaded. " \
133
- "Please update the formatter according to the documentation at: " \
134
- "https://docs.appsignal.com/ruby/instrumentation/event-formatters.html"
135
-
136
- logs = capture_logs do
137
- capture_std_streams(std_stream, err_stream) { deprecated_formatter }
138
- end
139
- expect(logs).to contains_log :warn, message
140
- expect(stderr).to include "appsignal WARNING: #{message}"
141
-
142
- expect(klass.deprecated_formatter_classes.keys).to include("mock.deprecated")
143
- end
144
-
145
- it "initializes deprecated formatters" do
146
- capture_std_streams(std_stream, err_stream) { deprecated_formatter }
147
- klass.initialize_deprecated_formatters
148
-
149
- expect(klass.registered?("mock.deprecated")).to be_truthy
150
- expect(klass.formatters["mock.deprecated"]).to be_instance_of(deprecated_formatter)
151
- expect(klass.deprecated_formatter_classes["mock.deprecated"]).to eq(deprecated_formatter)
152
- end
153
- end
154
117
  end
155
118
 
156
119
  describe ".registered?" do
@@ -1,6 +1,13 @@
1
1
  describe Appsignal::Extension, :extension_installation_failure do
2
2
  context "when the extension library cannot be loaded" do
3
+ # This test breaks the installation on purpose and is not run by default.
4
+ # See `rake test:failure`. If this test was run, run `rake
5
+ # extension:install` again to fix the extension installation.
3
6
  it "prints and logs an error" do
7
+ # ENV var to make sure installation fails on purpurse
8
+ ENV["_TEST_APPSIGNAL_EXTENSION_FAILURE"] = "true"
9
+ `rake extension:install` # Run installation
10
+
4
11
  require "open3"
5
12
  _stdout, stderr, _status = Open3.capture3("bin/appsignal --version")
6
13
  expect(stderr).to include("ERROR: AppSignal failed to load extension")
@@ -119,56 +119,22 @@ describe Appsignal::Extension do
119
119
  end
120
120
  end
121
121
 
122
- context "when the extension library cannot be loaded", :extension_installation_failure do
123
- let(:ext) { Appsignal::Extension }
122
+ context "when the extension library cannot be loaded" do
123
+ subject { Appsignal::Extension }
124
124
 
125
- around do |example|
126
- Appsignal::Testing.without_testing { example.run }
125
+ before do
126
+ allow(Appsignal).to receive(:extension_loaded).and_return(false)
127
+ allow(Appsignal).to receive(:testing?).and_return(false)
127
128
  end
128
129
 
129
130
  it "should indicate that the extension is not loaded" do
130
131
  expect(Appsignal.extension_loaded?).to be_falsy
131
132
  end
132
133
 
133
- it "does not raise errors when methods are called" do
134
- ext.appsignal_start
135
- ext.something
136
- end
137
-
138
- describe Appsignal::Extension::MockData do
139
- it "does not error on missing data_map_new extension method calls" do
140
- map = ext.data_map_new
141
- expect(map).to be_kind_of(Appsignal::Extension::MockData)
142
- # Does not raise errors any arbitrary method call that does not exist
143
- map.set_string("key", "value")
144
- map.set_int("key", 123)
145
- map.something
146
- end
147
-
148
- it "does not error on missing data_array_new extension method calls" do
149
- array = ext.data_array_new
150
- expect(array).to be_kind_of(Appsignal::Extension::MockData)
151
- # Does not raise errors any arbitrary method call that does not exist
152
- array.append_string("value")
153
- array.append_int(123)
154
- array.something
155
- end
156
- end
157
-
158
- describe Appsignal::Extension::MockTransaction do
159
- it "does not error on missing transaction extension method calls" do
160
- transaction = described_class.new
161
-
162
- transaction.start_event(0)
163
- transaction.finish_event(
164
- "name",
165
- "title",
166
- "body",
167
- Appsignal::EventFormatter::DEFAULT,
168
- 0
169
- )
170
- transaction.something
171
- end
134
+ it "should not raise errors when methods are called" do
135
+ expect do
136
+ subject.something
137
+ end.not_to raise_error
172
138
  end
173
139
  end
174
140
  end
@@ -2,8 +2,6 @@ describe Appsignal::Hooks::ActionCableHook do
2
2
  if DependencyHelper.action_cable_present?
3
3
  context "with ActionCable" do
4
4
  require "action_cable/engine"
5
- # Require test helper to test with ConnectionStub
6
- require "action_cable/channel/test_case" if DependencyHelper.rails6_present?
7
5
 
8
6
  describe ".dependencies_present?" do
9
7
  subject { described_class.new.dependencies_present? }
@@ -264,49 +262,6 @@ describe Appsignal::Hooks::ActionCableHook do
264
262
  )
265
263
  end
266
264
  end
267
-
268
- if DependencyHelper.rails6_present?
269
- context "with ConnectionStub" do
270
- let(:connection) { ActionCable::Channel::ConnectionStub.new }
271
- let(:transaction_id) { "Stubbed transaction id" }
272
- before do
273
- # Stub future (private AppSignal) transaction id generated by the hook.
274
- expect(SecureRandom).to receive(:uuid).and_return(transaction_id)
275
- end
276
-
277
- it "does not fail on missing `#env` method on `ConnectionStub`" do
278
- instance.subscribe_to_channel
279
-
280
- expect(subject).to include(
281
- "action" => "MyChannel#subscribed",
282
- "error" => nil,
283
- "id" => transaction_id,
284
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
285
- "metadata" => {
286
- "method" => "websocket",
287
- "path" => "" # No path as the ConnectionStub doesn't have the real request env
288
- }
289
- )
290
- expect(subject["events"].first).to include(
291
- "allocation_count" => kind_of(Integer),
292
- "body" => "",
293
- "body_format" => Appsignal::EventFormatter::DEFAULT,
294
- "child_allocation_count" => kind_of(Integer),
295
- "child_duration" => kind_of(Float),
296
- "child_gc_duration" => kind_of(Float),
297
- "count" => 1,
298
- "gc_duration" => kind_of(Float),
299
- "start" => kind_of(Float),
300
- "duration" => kind_of(Float),
301
- "name" => "subscribed.action_cable",
302
- "title" => ""
303
- )
304
- expect(subject["sample_data"]).to include(
305
- "params" => { "internal" => "true" }
306
- )
307
- end
308
- end
309
- end
310
265
  end
311
266
 
312
267
  describe "unsubscribe callback" do
@@ -394,49 +349,6 @@ describe Appsignal::Hooks::ActionCableHook do
394
349
  )
395
350
  end
396
351
  end
397
-
398
- if DependencyHelper.rails6_present?
399
- context "with ConnectionStub" do
400
- let(:connection) { ActionCable::Channel::ConnectionStub.new }
401
- let(:transaction_id) { "Stubbed transaction id" }
402
- before do
403
- # Stub future (private AppSignal) transaction id generated by the hook.
404
- expect(SecureRandom).to receive(:uuid).and_return(transaction_id)
405
- end
406
-
407
- it "does not fail on missing `#env` method on `ConnectionStub`" do
408
- instance.unsubscribe_from_channel
409
-
410
- expect(subject).to include(
411
- "action" => "MyChannel#unsubscribed",
412
- "error" => nil,
413
- "id" => transaction_id,
414
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
415
- "metadata" => {
416
- "method" => "websocket",
417
- "path" => "" # No path as the ConnectionStub doesn't have the real request env
418
- }
419
- )
420
- expect(subject["events"].first).to include(
421
- "allocation_count" => kind_of(Integer),
422
- "body" => "",
423
- "body_format" => Appsignal::EventFormatter::DEFAULT,
424
- "child_allocation_count" => kind_of(Integer),
425
- "child_duration" => kind_of(Float),
426
- "child_gc_duration" => kind_of(Float),
427
- "count" => 1,
428
- "gc_duration" => kind_of(Float),
429
- "start" => kind_of(Float),
430
- "duration" => kind_of(Float),
431
- "name" => "unsubscribed.action_cable",
432
- "title" => ""
433
- )
434
- expect(subject["sample_data"]).to include(
435
- "params" => { "internal" => "true" }
436
- )
437
- end
438
- end
439
- end
440
352
  end
441
353
  end
442
354
  end
@@ -3,6 +3,11 @@ describe Appsignal::Hooks::CelluloidHook do
3
3
  before :context do
4
4
  module Celluloid
5
5
  def self.shutdown
6
+ @shut_down = true
7
+ end
8
+
9
+ def self.shut_down?
10
+ @shut_down == true
6
11
  end
7
12
  end
8
13
  Appsignal::Hooks::CelluloidHook.new.install
@@ -18,7 +23,7 @@ describe Appsignal::Hooks::CelluloidHook do
18
23
  end
19
24
 
20
25
  specify { expect(Appsignal).to receive(:stop) }
21
- specify { expect(Celluloid).to receive(:shutdown_without_appsignal) }
26
+ specify { expect(Celluloid.shut_down?).to be true }
22
27
 
23
28
  after do
24
29
  Celluloid.shutdown
@@ -20,8 +20,7 @@ describe Appsignal::Hooks::RakeHook do
20
20
  end
21
21
 
22
22
  it "calls the original task" do
23
- expect(task).to receive(:execute_without_appsignal).with(arguments)
24
- perform
23
+ expect(perform).to eq([])
25
24
  end
26
25
  end
27
26
 
@@ -1,33 +1,68 @@
1
1
  describe Appsignal::Hooks::RedisHook do
2
2
  before do
3
3
  Appsignal.config = project_fixture_config
4
- Appsignal::Hooks.load_hooks
5
4
  end
6
5
 
7
6
  if DependencyHelper.redis_present?
8
7
  context "with redis" do
9
8
  context "with instrumentation enabled" do
10
- before do
11
- Appsignal.config.config_hash[:instrument_redis] = true
12
- allow_any_instance_of(Redis::Client).to receive(:process_without_appsignal).and_return(1)
13
- end
14
-
15
9
  describe "#dependencies_present?" do
16
10
  subject { described_class.new.dependencies_present? }
17
11
 
18
12
  it { is_expected.to be_truthy }
19
13
  end
20
14
 
21
- it "should instrument a redis call" do
22
- Appsignal::Transaction.create("uuid", Appsignal::Transaction::HTTP_REQUEST, "test")
23
- expect(Appsignal::Transaction.current).to receive(:start_event)
24
- .at_least(:once)
25
- expect(Appsignal::Transaction.current).to receive(:finish_event)
26
- .at_least(:once)
27
- .with("query.redis", "redis://127.0.0.1:6379/0", "get ?", 0)
15
+ describe "integration" do
16
+ before do
17
+ Appsignal.config.config_hash[:instrument_redis] = true
18
+ end
19
+
20
+ context "install" do
21
+ before do
22
+ Appsignal::Hooks.load_hooks
23
+ end
24
+
25
+ it "does something" do
26
+ # Test if the last included module (prepended module) was our
27
+ # integration. That's not certain with the assertions below
28
+ # because we have to overwrite the `process` method for the test.
29
+ expect(Redis::Client.included_modules.first)
30
+ .to eql(Appsignal::Integrations::RedisIntegration)
31
+ end
32
+ end
33
+
34
+ context "instrumentation" do
35
+ before do
36
+ # Stub Redis::Client class so that it doesn't perform an actual
37
+ # Redis query. This class will be included (prepended) with the
38
+ # AppSignal Redis integration.
39
+ stub_const("Redis::Client", Class.new do
40
+ def id
41
+ :stub_id
42
+ end
43
+
44
+ def process(_commands)
45
+ :stub_process
46
+ end
47
+ end)
48
+ # Load the integration again for the stubbed Redis::Client class.
49
+ # Call it directly because {Appsignal::Hooks.load_hooks} keeps
50
+ # track if it was installed already or not.
51
+ Appsignal::Hooks::RedisHook.new.install
52
+ end
53
+
54
+ it "instrument a redis call" do
55
+ Appsignal::Transaction.create("uuid", Appsignal::Transaction::HTTP_REQUEST, "test")
56
+ expect(Appsignal::Transaction.current).to receive(:start_event)
57
+ .at_least(:once)
58
+ expect(Appsignal::Transaction.current).to receive(:finish_event)
59
+ .at_least(:once)
60
+ .with("query.redis", :stub_id, "get ?", 0)
28
61
 
29
- client = Redis::Client.new
30
- expect(client.process([[:get, "key"]])).to eq 1
62
+ client = Redis::Client.new
63
+ expect(client.process([[:get, "key"]])).to eql(:stub_process)
64
+ end
65
+ end
31
66
  end
32
67
  end
33
68