appsignal 4.0.6-java → 4.0.7-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Rakefile +9 -9
  4. data/appsignal.gemspec +22 -1
  5. data/ext/agent.rb +27 -27
  6. data/lib/appsignal/check_in.rb +1 -1
  7. data/lib/appsignal/config.rb +1 -3
  8. data/lib/appsignal/integrations/resque.rb +1 -6
  9. data/lib/appsignal/utils/hash_sanitizer.rb +4 -0
  10. data/lib/appsignal/version.rb +1 -1
  11. metadata +2 -192
  12. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  13. data/.github/ISSUE_TEMPLATE/chore.md +0 -14
  14. data/.github/workflows/ci.yml +0 -3285
  15. data/.github/workflows/create_release_from_tag.yml +0 -62
  16. data/.gitignore +0 -35
  17. data/.gitmodules +0 -3
  18. data/.rspec +0 -4
  19. data/.yardopts +0 -8
  20. data/benchmark.rake +0 -139
  21. data/gemfiles/capistrano2.gemfile +0 -6
  22. data/gemfiles/capistrano3.gemfile +0 -7
  23. data/gemfiles/dry-monitor.gemfile +0 -5
  24. data/gemfiles/grape.gemfile +0 -5
  25. data/gemfiles/hanami-2.0.gemfile +0 -7
  26. data/gemfiles/hanami-2.1.gemfile +0 -7
  27. data/gemfiles/http5.gemfile +0 -5
  28. data/gemfiles/no_dependencies.gemfile +0 -10
  29. data/gemfiles/padrino.gemfile +0 -7
  30. data/gemfiles/psych-3.gemfile +0 -5
  31. data/gemfiles/psych-4.gemfile +0 -5
  32. data/gemfiles/que-1.gemfile +0 -5
  33. data/gemfiles/que-2.gemfile +0 -5
  34. data/gemfiles/rails-6.0.gemfile +0 -10
  35. data/gemfiles/rails-6.1.gemfile +0 -11
  36. data/gemfiles/rails-7.0.gemfile +0 -11
  37. data/gemfiles/rails-7.1.gemfile +0 -11
  38. data/gemfiles/rails-7.2.gemfile +0 -11
  39. data/gemfiles/redis-4.gemfile +0 -5
  40. data/gemfiles/redis-5.gemfile +0 -6
  41. data/gemfiles/resque-2.gemfile +0 -6
  42. data/gemfiles/sequel.gemfile +0 -10
  43. data/gemfiles/sinatra.gemfile +0 -5
  44. data/gemfiles/webmachine1.gemfile +0 -7
  45. data/gemfiles/webmachine2.gemfile +0 -6
  46. data/mono.yml +0 -16
  47. data/spec/.rubocop.yml +0 -7
  48. data/spec/lib/appsignal/auth_check_spec.rb +0 -84
  49. data/spec/lib/appsignal/capistrano2_spec.rb +0 -227
  50. data/spec/lib/appsignal/capistrano3_spec.rb +0 -284
  51. data/spec/lib/appsignal/check_in/cron_spec.rb +0 -210
  52. data/spec/lib/appsignal/check_in/scheduler_spec.rb +0 -557
  53. data/spec/lib/appsignal/cli/demo_spec.rb +0 -46
  54. data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +0 -16
  55. data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +0 -86
  56. data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1553
  57. data/spec/lib/appsignal/cli/helpers_spec.rb +0 -179
  58. data/spec/lib/appsignal/cli/install_spec.rb +0 -848
  59. data/spec/lib/appsignal/cli_spec.rb +0 -56
  60. data/spec/lib/appsignal/config_spec.rb +0 -1380
  61. data/spec/lib/appsignal/demo_spec.rb +0 -83
  62. data/spec/lib/appsignal/environment_spec.rb +0 -190
  63. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +0 -60
  64. data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +0 -21
  65. data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +0 -21
  66. data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +0 -52
  67. data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +0 -21
  68. data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +0 -84
  69. data/spec/lib/appsignal/event_formatter/rom/sql_formatter_spec.rb +0 -22
  70. data/spec/lib/appsignal/event_formatter/sequel/sql_formatter_spec.rb +0 -30
  71. data/spec/lib/appsignal/event_formatter/view_component/render_formatter_spec.rb +0 -41
  72. data/spec/lib/appsignal/event_formatter_spec.rb +0 -193
  73. data/spec/lib/appsignal/extension/jruby_spec.rb +0 -46
  74. data/spec/lib/appsignal/extension_install_failure_spec.rb +0 -20
  75. data/spec/lib/appsignal/extension_spec.rb +0 -178
  76. data/spec/lib/appsignal/garbage_collection_spec.rb +0 -98
  77. data/spec/lib/appsignal/hooks/action_cable_spec.rb +0 -345
  78. data/spec/lib/appsignal/hooks/action_mailer_spec.rb +0 -55
  79. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +0 -23
  80. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +0 -99
  81. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +0 -47
  82. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +0 -47
  83. data/spec/lib/appsignal/hooks/activejob_spec.rb +0 -650
  84. data/spec/lib/appsignal/hooks/at_exit_spec.rb +0 -105
  85. data/spec/lib/appsignal/hooks/celluloid_spec.rb +0 -40
  86. data/spec/lib/appsignal/hooks/data_mapper_spec.rb +0 -40
  87. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +0 -38
  88. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +0 -83
  89. data/spec/lib/appsignal/hooks/excon_spec.rb +0 -67
  90. data/spec/lib/appsignal/hooks/gvl_spec.rb +0 -145
  91. data/spec/lib/appsignal/hooks/http_spec.rb +0 -37
  92. data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +0 -46
  93. data/spec/lib/appsignal/hooks/mri_spec.rb +0 -23
  94. data/spec/lib/appsignal/hooks/net_http_spec.rb +0 -18
  95. data/spec/lib/appsignal/hooks/passenger_spec.rb +0 -30
  96. data/spec/lib/appsignal/hooks/puma_spec.rb +0 -80
  97. data/spec/lib/appsignal/hooks/que_spec.rb +0 -19
  98. data/spec/lib/appsignal/hooks/rake_spec.rb +0 -144
  99. data/spec/lib/appsignal/hooks/redis_client_spec.rb +0 -218
  100. data/spec/lib/appsignal/hooks/redis_spec.rb +0 -124
  101. data/spec/lib/appsignal/hooks/resque_spec.rb +0 -27
  102. data/spec/lib/appsignal/hooks/sequel_spec.rb +0 -44
  103. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -29
  104. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +0 -115
  105. data/spec/lib/appsignal/hooks/unicorn_spec.rb +0 -63
  106. data/spec/lib/appsignal/hooks/webmachine_spec.rb +0 -24
  107. data/spec/lib/appsignal/hooks_spec.rb +0 -124
  108. data/spec/lib/appsignal/integrations/data_mapper_spec.rb +0 -74
  109. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +0 -454
  110. data/spec/lib/appsignal/integrations/http_spec.rb +0 -111
  111. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +0 -154
  112. data/spec/lib/appsignal/integrations/net_http_spec.rb +0 -33
  113. data/spec/lib/appsignal/integrations/object_spec.rb +0 -347
  114. data/spec/lib/appsignal/integrations/puma_spec.rb +0 -150
  115. data/spec/lib/appsignal/integrations/que_spec.rb +0 -187
  116. data/spec/lib/appsignal/integrations/railtie_spec.rb +0 -457
  117. data/spec/lib/appsignal/integrations/resque_spec.rb +0 -155
  118. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +0 -165
  119. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +0 -640
  120. data/spec/lib/appsignal/integrations/webmachine_spec.rb +0 -136
  121. data/spec/lib/appsignal/loaders/grape_spec.rb +0 -12
  122. data/spec/lib/appsignal/loaders/hanami_spec.rb +0 -92
  123. data/spec/lib/appsignal/loaders/padrino_spec.rb +0 -273
  124. data/spec/lib/appsignal/loaders/sinatra_spec.rb +0 -44
  125. data/spec/lib/appsignal/loaders_spec.rb +0 -144
  126. data/spec/lib/appsignal/logger_spec.rb +0 -205
  127. data/spec/lib/appsignal/marker_spec.rb +0 -51
  128. data/spec/lib/appsignal/probes/gvl_spec.rb +0 -164
  129. data/spec/lib/appsignal/probes/mri_spec.rb +0 -162
  130. data/spec/lib/appsignal/probes/sidekiq_spec.rb +0 -333
  131. data/spec/lib/appsignal/probes_spec.rb +0 -414
  132. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +0 -370
  133. data/spec/lib/appsignal/rack/body_wrapper_spec.rb +0 -319
  134. data/spec/lib/appsignal/rack/event_handler_spec.rb +0 -441
  135. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +0 -201
  136. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +0 -36
  137. data/spec/lib/appsignal/rack/instrumentation_middleware_spec.rb +0 -38
  138. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +0 -126
  139. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +0 -217
  140. data/spec/lib/appsignal/rack_spec.rb +0 -243
  141. data/spec/lib/appsignal/sample_data_spec.rb +0 -238
  142. data/spec/lib/appsignal/span_spec.rb +0 -141
  143. data/spec/lib/appsignal/system_spec.rb +0 -126
  144. data/spec/lib/appsignal/transaction_spec.rb +0 -2115
  145. data/spec/lib/appsignal/transmitter_spec.rb +0 -198
  146. data/spec/lib/appsignal/utils/data_spec.rb +0 -166
  147. data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +0 -182
  148. data/spec/lib/appsignal/utils/integration_logger_spec.rb +0 -21
  149. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -153
  150. data/spec/lib/appsignal/utils/json_spec.rb +0 -44
  151. data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +0 -192
  152. data/spec/lib/appsignal_spec.rb +0 -1919
  153. data/spec/lib/puma/appsignal_spec.rb +0 -334
  154. data/spec/spec_helper.rb +0 -179
  155. data/spec/support/fixtures/generated_config.yml +0 -24
  156. data/spec/support/fixtures/projects/broken/config/appsignal.yml +0 -1
  157. data/spec/support/fixtures/projects/valid/config/appsignal.yml +0 -57
  158. data/spec/support/fixtures/projects/valid/log/.gitkeep +0 -0
  159. data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +0 -16
  160. data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +0 -56
  161. data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +0 -10
  162. data/spec/support/fixtures/projects/valid_with_rails_app/log/.gitkeep +0 -0
  163. data/spec/support/fixtures/uploaded_file.txt +0 -0
  164. data/spec/support/hanami/hanami_app.rb +0 -29
  165. data/spec/support/helpers/action_mailer_helpers.rb +0 -25
  166. data/spec/support/helpers/activejob_helpers.rb +0 -27
  167. data/spec/support/helpers/api_request_helper.rb +0 -60
  168. data/spec/support/helpers/cli_helpers.rb +0 -40
  169. data/spec/support/helpers/config_helpers.rb +0 -66
  170. data/spec/support/helpers/dependency_helper.rb +0 -155
  171. data/spec/support/helpers/directory_helper.rb +0 -27
  172. data/spec/support/helpers/env_helpers.rb +0 -41
  173. data/spec/support/helpers/environment_metdata_helper.rb +0 -16
  174. data/spec/support/helpers/example_exception.rb +0 -13
  175. data/spec/support/helpers/example_standard_error.rb +0 -13
  176. data/spec/support/helpers/loader_helper.rb +0 -21
  177. data/spec/support/helpers/log_helpers.rb +0 -36
  178. data/spec/support/helpers/rails_helper.rb +0 -28
  179. data/spec/support/helpers/std_streams_helper.rb +0 -94
  180. data/spec/support/helpers/system_helpers.rb +0 -8
  181. data/spec/support/helpers/take_at_most_helper.rb +0 -21
  182. data/spec/support/helpers/time_helpers.rb +0 -11
  183. data/spec/support/helpers/transaction_helpers.rb +0 -122
  184. data/spec/support/helpers/wait_for_helper.rb +0 -39
  185. data/spec/support/matchers/contains_log.rb +0 -26
  186. data/spec/support/matchers/have_colorized_text.rb +0 -28
  187. data/spec/support/matchers/transaction.rb +0 -200
  188. data/spec/support/mocks/appsignal_mock.rb +0 -18
  189. data/spec/support/mocks/dummy_app.rb +0 -20
  190. data/spec/support/mocks/fake_gc_profiler.rb +0 -19
  191. data/spec/support/mocks/fake_gvl_tools.rb +0 -28
  192. data/spec/support/mocks/hash_like.rb +0 -10
  193. data/spec/support/mocks/mock_probe.rb +0 -13
  194. data/spec/support/mocks/puma_mock.rb +0 -43
  195. data/spec/support/shared_examples/instrument.rb +0 -48
  196. data/spec/support/stubs/appsignal/loaders/loader_stub.rb +0 -7
  197. data/spec/support/stubs/delayed_job.rb +0 -0
  198. data/spec/support/stubs/sidekiq/api.rb +0 -4
  199. data/spec/support/testing.rb +0 -203
  200. data/support/bundler_wrapper +0 -12
  201. data/support/install_deps +0 -33
@@ -1,414 +0,0 @@
1
- describe Appsignal::Probes do
2
- include WaitForHelper
3
-
4
- before { Appsignal::Probes.probes.clear }
5
-
6
- it "returns a ProbeCollection" do
7
- expect(Appsignal::Probes.probes)
8
- .to be_instance_of(Appsignal::Probes::ProbeCollection)
9
- end
10
-
11
- describe ".start" do
12
- class ProbeWithoutDependency < MockProbe
13
- def self.dependencies_present?
14
- true
15
- end
16
- end
17
-
18
- class ProbeWithMissingDependency < MockProbe
19
- def self.dependencies_present?
20
- false
21
- end
22
- end
23
-
24
- class BrokenProbe < MockProbe
25
- def call
26
- super
27
- raise "oh no!"
28
- end
29
- end
30
-
31
- class BrokenProbeOnInitialize < MockProbe
32
- def initialize
33
- super
34
- raise "oh no initialize!"
35
- end
36
-
37
- def call
38
- true
39
- end
40
- end
41
-
42
- let(:log_stream) { StringIO.new }
43
- let(:log) { log_contents(log_stream) }
44
- before do
45
- Appsignal.internal_logger = test_logger(log_stream)
46
- # TODO: These logs are here to debug an issue on CI
47
- Appsignal.internal_logger.info("a" * 100)
48
- Appsignal.internal_logger.info("b" * 100)
49
- speed_up_tests!
50
- end
51
-
52
- describe ".started?" do
53
- it "returns true when the probes thread has been started" do
54
- expect(Appsignal::Probes.started?).to be_falsy
55
- Appsignal::Probes.register :my_probe, lambda {}
56
- Appsignal::Probes.start
57
- expect(Appsignal::Probes.started?).to be_truthy
58
- end
59
-
60
- it "returns false when the probes thread has been stopped" do
61
- Appsignal::Probes.register :my_probe, lambda {}
62
- Appsignal::Probes.start
63
- expect(Appsignal::Probes.started?).to be_truthy
64
- Appsignal::Probes.stop
65
- expect(Appsignal::Probes.started?).to be_falsy
66
- end
67
- end
68
-
69
- context "with an instance of a class" do
70
- it "calls the probe every <wait_time>" do
71
- probe = MockProbe.new
72
- Appsignal::Probes.register :my_probe, probe
73
- Appsignal::Probes.start
74
-
75
- wait_for("enough probe calls") { probe.calls >= 2 }
76
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
77
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
78
- end
79
-
80
- context "when dependency requirement is not met" do
81
- it "does not initialize the probe" do
82
- # Working probe which we can use to wait for X ticks
83
- working_probe = ProbeWithoutDependency.new
84
- Appsignal::Probes.register :probe_without_dep, working_probe
85
-
86
- probe = ProbeWithMissingDependency.new
87
- Appsignal::Probes.register :probe_with_missing_dep, probe
88
- Appsignal::Probes.start
89
-
90
- wait_for("enough probe calls") { working_probe.calls >= 2 }
91
- # Only counts initialized probes
92
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
93
- expect(log).to contains_log :debug, "Skipping 'probe_with_missing_dep' probe, " \
94
- "ProbeWithMissingDependency.dependency_present? returned falsy"
95
- end
96
- end
97
- end
98
-
99
- context "with probe class" do
100
- it "creates an instance of the class and call that every <wait time>" do
101
- probe = MockProbe
102
- Appsignal::Probes.register :my_probe, probe
103
- Appsignal::Probes.start
104
-
105
- wait_for("enough probe calls") { Appsignal::Testing.store[:mock_probe_call] >= 2 }
106
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
107
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
108
- end
109
-
110
- context "when dependency requirement is not met" do
111
- it "does not initialize the probe" do
112
- # Working probe which we can use to wait for X ticks
113
- working_probe = ProbeWithoutDependency
114
- Appsignal::Probes.register :probe_without_dep, working_probe
115
-
116
- probe = ProbeWithMissingDependency
117
- Appsignal::Probes.register :probe_with_missing_dep, probe
118
- Appsignal::Probes.start
119
-
120
- wait_for("enough probe calls") { Appsignal::Testing.store[:mock_probe_call] >= 2 }
121
- # Only counts initialized probes
122
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
123
- expect(log).to contains_log :debug, "Skipping 'probe_with_missing_dep' probe, " \
124
- "ProbeWithMissingDependency.dependency_present? returned falsy"
125
- end
126
- end
127
-
128
- context "when there is a problem initializing the probe" do
129
- it "logs an error" do
130
- # Working probe which we can use to wait for X ticks
131
- working_probe = ProbeWithoutDependency
132
- Appsignal::Probes.register :probe_without_dep, working_probe
133
-
134
- probe = BrokenProbeOnInitialize
135
- Appsignal::Probes.register :broken_probe_on_initialize, probe
136
- Appsignal::Probes.start
137
-
138
- wait_for("enough probe calls") { Appsignal::Testing.store[:mock_probe_call] >= 2 }
139
- # Only counts initialized probes
140
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
141
- # Logs error
142
- expect(log).to contains_log(
143
- :error,
144
- "Error while initializing minutely probe 'broken_probe_on_initialize': " \
145
- "oh no initialize!"
146
- )
147
- # Start of the error backtrace as debug log
148
- expect(log).to contains_log :debug, File.expand_path("../../..", __dir__)
149
- end
150
- end
151
- end
152
-
153
- context "with a lambda" do
154
- it "calls the lambda every <wait time>" do
155
- calls = 0
156
- probe = lambda { calls += 1 }
157
- Appsignal::Probes.register :my_probe, probe
158
- Appsignal::Probes.start
159
-
160
- wait_for("enough probe calls") { calls >= 2 }
161
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
162
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
163
- end
164
- end
165
-
166
- context "with a broken probe" do
167
- it "logs the error and continues calling the probes every <wait_time>" do
168
- probe = MockProbe.new
169
- broken_probe = BrokenProbe.new
170
- Appsignal::Probes.register :my_probe, probe
171
- Appsignal::Probes.register :broken_probe, broken_probe
172
- Appsignal::Probes.start
173
-
174
- wait_for("enough probe calls") { probe.calls >= 2 }
175
- wait_for("enough broken_probe calls") { broken_probe.calls >= 2 }
176
-
177
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 2 probes")
178
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
179
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 'broken_probe' probe")
180
- expect(log).to contains_log(:error, "Error in minutely probe 'broken_probe': oh no!")
181
- gem_path = File.expand_path("../../..", __dir__) # Start of backtrace
182
- expect(log).to contains_log(:debug, gem_path)
183
- end
184
- end
185
-
186
- context "with a probe that takes 60 seconds" do
187
- it "logs an error and continues calling the probes every <wait_time>" do
188
- stub_const("Appsignal::Probes::ITERATION_IN_SECONDS", 0.2)
189
- calls = 0
190
- probe = lambda do
191
- calls += 1
192
- sleep 0.2
193
- end
194
- Appsignal::Probes.register :my_probe, probe
195
- Appsignal::Probes.register :other_probe, lambda {}
196
- Appsignal::Probes.start
197
-
198
- wait_for("enough probe calls") { calls >= 2 }
199
-
200
- expect(log).to contains_log(
201
- :error,
202
- "The minutely probes took more than 60 seconds. " \
203
- "The probes should not take this long as metrics will not " \
204
- "be accurately reported."
205
- )
206
- end
207
- end
208
-
209
- it "ensures only one minutely probes thread is active at a time" do
210
- alive_thread_counter = proc { Thread.list.reject { |t| t.status == "dead" }.length }
211
- probe = MockProbe.new
212
- Appsignal::Probes.register :my_probe, probe
213
- expect do
214
- Appsignal::Probes.start
215
- end.to change { alive_thread_counter.call }.by(1)
216
-
217
- wait_for("enough probe calls") { probe.calls >= 2 }
218
- expect(Appsignal::Probes).to have_received(:initial_wait_time).once
219
- expect(Appsignal::Probes).to have_received(:wait_time).at_least(:once)
220
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
221
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
222
-
223
- # Starting twice in this spec, so expecting it more than once
224
- expect(Appsignal::Probes).to have_received(:initial_wait_time).once
225
- expect do
226
- # Fetch old thread
227
- thread = Appsignal::Probes.instance_variable_get(:@thread)
228
- Appsignal::Probes.start
229
- thread&.join # Wait for old thread to exit
230
- end.to_not(change { alive_thread_counter.call })
231
- end
232
-
233
- context "with thread already started" do
234
- it "auto starts probes added after the thread is started" do
235
- Appsignal::Probes.start
236
- wait_for("Probes thread to start") { Appsignal::Probes.started? }
237
-
238
- calls = 0
239
- probe = lambda { calls += 1 }
240
- Appsignal::Probes.register :late_probe, probe
241
-
242
- wait_for("enough probe calls") { calls >= 2 }
243
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
244
- expect(log).to contains_log(:debug, "Gathering minutely metrics with 'late_probe' probe")
245
- end
246
- end
247
- end
248
-
249
- describe ".unregister" do
250
- before { speed_up_tests! }
251
-
252
- it "does not call the initialized probe after unregistering" do
253
- probe1_calls = 0
254
- probe2_calls = 0
255
- probe1 = lambda { probe1_calls += 1 }
256
- probe2 = lambda { probe2_calls += 1 }
257
- Appsignal::Probes.register :probe1, probe1
258
- Appsignal::Probes.register :probe2, probe2
259
- Appsignal::Probes.start
260
- wait_for("enough probe1 calls") { probe1_calls >= 2 }
261
- wait_for("enough probe2 calls") { probe2_calls >= 2 }
262
-
263
- Appsignal::Probes.unregister :probe2
264
- probe1_calls = 0
265
- probe2_calls = 0
266
- # Check the probe 1 calls to make sure the probes have been called before
267
- # testing if the unregistered probe has not been called
268
- wait_for("enough probe1 calls") { probe1_calls >= 2 }
269
- expect(probe2_calls).to eq(0)
270
- end
271
- end
272
-
273
- describe ".stop" do
274
- before do
275
- speed_up_tests!
276
- end
277
-
278
- it "stops the minutely thread" do
279
- Appsignal::Probes.start
280
- thread = Appsignal::Probes.instance_variable_get(:@thread)
281
- expect(%w[sleep run]).to include(thread.status)
282
- Appsignal::Probes.stop
283
- thread.join
284
- expect(thread.status).to eql(false)
285
- end
286
-
287
- it "clears the probe instances array" do
288
- Appsignal::Probes.register :my_probe, lambda {}
289
- Appsignal::Probes.start
290
- thread = Appsignal::Probes.instance_variable_get(:@thread)
291
- wait_for("probes initialized") do
292
- !Appsignal::Probes.send(:probe_instances).empty?
293
- end
294
- expect(Appsignal::Probes.send(:probe_instances)).to_not be_empty
295
- Appsignal::Probes.stop
296
- thread.join
297
- expect(Appsignal::Probes.send(:probe_instances)).to be_empty
298
- end
299
- end
300
-
301
- describe ".wait_time" do
302
- it "gets the time to the next minute" do
303
- time = Time.new(2019, 4, 9, 12, 0, 20)
304
- Timecop.freeze time do
305
- expect(Appsignal::Probes.wait_time).to eq 40
306
- end
307
- end
308
- end
309
-
310
- describe ".initial_wait_time" do
311
- context "when started in the last 30 seconds of a minute" do
312
- it "waits for the number of seconds + 60" do
313
- time = Time.new(2019, 4, 9, 12, 0, 31)
314
- Timecop.freeze time do
315
- expect(Appsignal::Probes.send(:initial_wait_time)).to eql(29 + 60)
316
- end
317
- end
318
- end
319
-
320
- context "when started in the first 30 seconds of a minute" do
321
- it "waits the remaining seconds in the minute" do
322
- time = Time.new(2019, 4, 9, 12, 0, 29)
323
- Timecop.freeze time do
324
- expect(Appsignal::Probes.send(:initial_wait_time)).to eql(31)
325
- end
326
- end
327
- end
328
- end
329
-
330
- describe Appsignal::Probes::ProbeCollection do
331
- let(:collection) { described_class.new }
332
-
333
- describe "#count" do
334
- it "returns how many probes are registered" do
335
- expect(collection.count).to eql(0)
336
- collection.internal_register :my_probe_1, lambda {}
337
- expect(collection.count).to eql(1)
338
- collection.internal_register :my_probe_2, lambda {}
339
- expect(collection.count).to eql(2)
340
- end
341
- end
342
-
343
- describe "#clear" do
344
- it "clears the list of probes" do
345
- collection.internal_register :my_probe_1, lambda {}
346
- collection.internal_register :my_probe_2, lambda {}
347
- expect(collection.count).to eql(2)
348
- collection.clear
349
- expect(collection.count).to eql(0)
350
- end
351
- end
352
-
353
- describe "#[]" do
354
- it "returns the probe for that name" do
355
- probe = lambda {}
356
- collection.internal_register :my_probe, probe
357
- expect(collection[:my_probe]).to eql(probe)
358
- end
359
- end
360
-
361
- describe "#internal_register" do
362
- let(:log_stream) { std_stream }
363
- let(:log) { log_contents(log_stream) }
364
- before { Appsignal.internal_logger = test_logger(log_stream) }
365
-
366
- it "adds the probe by key" do
367
- probe = lambda {}
368
- collection.internal_register :my_probe, probe
369
- expect(collection[:my_probe]).to eql(probe)
370
- end
371
-
372
- context "when a probe is already registered with the same key" do
373
- it "logs a debug message" do
374
- probe = lambda {}
375
- collection.internal_register :my_probe, probe
376
- collection.internal_register :my_probe, probe
377
- expect(log).to contains_log :debug, "A probe with the name " \
378
- "`my_probe` is already registered. Overwriting the entry " \
379
- "with the new probe."
380
- expect(collection[:my_probe]).to eql(probe)
381
- end
382
- end
383
- end
384
-
385
- describe "#unregister" do
386
- it "removes the probe from the collection" do
387
- probe = lambda {}
388
- silence { collection.internal_register :my_probe, probe }
389
- expect(collection[:my_probe]).to eql(probe)
390
-
391
- silence { collection.unregister :my_probe }
392
- expect(collection[:my_probe]).to be_nil
393
- end
394
- end
395
-
396
- describe "#each" do
397
- it "loops over the registered probes" do
398
- probe = lambda {}
399
- collection.internal_register :my_probe, probe
400
- list = []
401
- collection.each do |name, p| # rubocop:disable Style/MapIntoArray
402
- list << [name, p]
403
- end
404
- expect(list).to eql([[:my_probe, probe]])
405
- end
406
- end
407
- end
408
-
409
- # Speed up test time by decreasing wait times in the probes mechanism
410
- def speed_up_tests!
411
- allow(Appsignal::Probes).to receive(:initial_wait_time).and_return(0.001)
412
- allow(Appsignal::Probes).to receive(:wait_time).and_return(0.001)
413
- end
414
- end