test-prof 0.12.0 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +155 -463
  3. data/README.md +9 -9
  4. data/config/default.yml +0 -15
  5. data/config/rubocop-rspec.yml +6 -0
  6. data/lib/test_prof/any_fixture/dump/base_adapter.rb +43 -0
  7. data/lib/test_prof/any_fixture/dump/digest.rb +29 -0
  8. data/lib/test_prof/any_fixture/dump/postgresql.rb +91 -0
  9. data/lib/test_prof/any_fixture/dump/sqlite.rb +42 -0
  10. data/lib/test_prof/any_fixture/dump.rb +212 -0
  11. data/lib/test_prof/any_fixture.rb +117 -8
  12. data/lib/test_prof/before_all/adapters/active_record.rb +15 -5
  13. data/lib/test_prof/before_all.rb +11 -2
  14. data/lib/test_prof/cops/rspec/aggregate_examples/its.rb +1 -1
  15. data/lib/test_prof/cops/rspec/aggregate_examples/line_range_helpers.rb +1 -1
  16. data/lib/test_prof/cops/rspec/aggregate_examples/matchers_with_side_effects.rb +1 -1
  17. data/lib/test_prof/cops/rspec/aggregate_examples/metadata_helpers.rb +1 -1
  18. data/lib/test_prof/cops/rspec/aggregate_examples/node_matchers.rb +1 -1
  19. data/lib/test_prof/cops/rspec/aggregate_examples.rb +1 -1
  20. data/lib/test_prof/event_prof/custom_events.rb +1 -1
  21. data/lib/test_prof/event_prof/instrumentations/active_support.rb +1 -1
  22. data/lib/test_prof/event_prof/profiler.rb +3 -4
  23. data/lib/test_prof/factory_prof/nate_heckler.rb +16 -0
  24. data/lib/test_prof/factory_prof/printers/flamegraph.rb +1 -1
  25. data/lib/test_prof/factory_prof/printers/nate_heckler.rb +26 -0
  26. data/lib/test_prof/factory_prof/printers/simple.rb +6 -2
  27. data/lib/test_prof/factory_prof.rb +24 -4
  28. data/lib/test_prof/logging.rb +18 -12
  29. data/lib/test_prof/recipes/logging.rb +1 -1
  30. data/lib/test_prof/recipes/minitest/before_all.rb +126 -24
  31. data/lib/test_prof/recipes/rspec/any_fixture.rb +1 -1
  32. data/lib/test_prof/recipes/rspec/before_all.rb +11 -3
  33. data/lib/test_prof/recipes/rspec/let_it_be.rb +6 -8
  34. data/lib/test_prof/rspec_dissect.rb +2 -2
  35. data/lib/test_prof/rspec_stamp.rb +1 -1
  36. data/lib/test_prof/rubocop.rb +0 -1
  37. data/lib/test_prof/ruby_prof.rb +11 -9
  38. data/lib/test_prof/tag_prof/result.rb +1 -1
  39. data/lib/test_prof/tag_prof/rspec.rb +3 -5
  40. data/lib/test_prof/utils/sized_ordered_set.rb +2 -2
  41. data/lib/test_prof/version.rb +1 -1
  42. data/lib/test_prof.rb +17 -4
  43. metadata +19 -14
  44. data/lib/test_prof/cops/rspec/aggregate_failures.rb +0 -26
  45. data/lib/test_prof/ext/active_record_3.rb +0 -27
  46. data/lib/test_prof/recipes/active_record_one_love.rb +0 -6
  47. data/lib/test_prof/recipes/active_record_shared_connection.rb +0 -77
@@ -38,7 +38,7 @@ module TestProf
38
38
  attr_accessor :top_count, :let_stats_enabled,
39
39
  :let_top_count
40
40
 
41
- alias let_stats_enabled? let_stats_enabled
41
+ alias_method :let_stats_enabled?, :let_stats_enabled
42
42
 
43
43
  attr_reader :mode
44
44
 
@@ -139,7 +139,7 @@ end
139
139
 
140
140
  require "test_prof/rspec_dissect/collectors/let"
141
141
  require "test_prof/rspec_dissect/collectors/before"
142
- require "test_prof/rspec_dissect/rspec" if TestProf.rspec?
142
+ require "test_prof/rspec_dissect/rspec"
143
143
 
144
144
  TestProf.activate("RD_PROF") do
145
145
  TestProf::RSpecDissect.init
@@ -39,7 +39,7 @@ module TestProf
39
39
  acc << if v.nil?
40
40
  k.to_sym
41
41
  else
42
- Hash[k.to_sym, v.to_sym]
42
+ {k.to_sym => v.to_sym}
43
43
  end
44
44
  end
45
45
  end
@@ -11,4 +11,3 @@ require "rubocop"
11
11
 
12
12
  require_relative "cops/inject"
13
13
  require "test_prof/cops/rspec/aggregate_examples"
14
- require "test_prof/cops/rspec/aggregate_failures"
@@ -239,16 +239,18 @@ module TestProf
239
239
  end
240
240
 
241
241
  def exclude_common_methods(profiler)
242
- profiler.exclude_methods!(
243
- TSort,
244
- :tsort_each
245
- )
242
+ if defined?(TSort)
243
+ profiler.exclude_methods!(
244
+ TSort,
245
+ :tsort_each
246
+ )
246
247
 
247
- profiler.exclude_methods!(
248
- TSort.singleton_class,
249
- :tsort_each, :each_strongly_connected_component,
250
- :each_strongly_connected_component_from
251
- )
248
+ profiler.exclude_methods!(
249
+ TSort.singleton_class,
250
+ :tsort_each, :each_strongly_connected_component,
251
+ :each_strongly_connected_component_from
252
+ )
253
+ end
252
254
 
253
255
  profiler.exclude_methods!(
254
256
  BasicObject,
@@ -12,7 +12,7 @@ module TestProf
12
12
 
13
13
  @data = Hash.new do |h, k|
14
14
  h[k] = {value: k, count: 0, time: 0.0}
15
- h[k].merge!(Hash[events.map { |event| [event, 0.0] }]) unless
15
+ h[k].merge!(events.map { |event| [event, 0.0] }.to_h) unless
16
16
  events.empty?
17
17
  h[k]
18
18
  end
@@ -53,11 +53,9 @@ module TestProf
53
53
  def fetch_events_data
54
54
  return {} unless @events_profiler
55
55
 
56
- Hash[
57
- @events_profiler.profilers.map do |profiler|
58
- [profiler.event, profiler.time]
59
- end
60
- ]
56
+ @events_profiler.profilers.map do |profiler|
57
+ [profiler.event, profiler.time]
58
+ end.to_h
61
59
  end
62
60
  end
63
61
  end
@@ -14,7 +14,7 @@ module TestProf
14
14
  def initialize(max_size, sort_by: nil, &block)
15
15
  @max_size = max_size
16
16
  @comparator =
17
- if block_given?
17
+ if block
18
18
  block
19
19
  elsif !sort_by.nil?
20
20
  ->(x, y) { x[sort_by] >= y[sort_by] }
@@ -42,7 +42,7 @@ module TestProf
42
42
  end
43
43
 
44
44
  def each(&block)
45
- if block_given?
45
+ if block
46
46
  data.each(&block)
47
47
  else
48
48
  data.each
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestProf
4
- VERSION = "0.12.0"
4
+ VERSION = "1.0.7"
5
5
  end
data/lib/test_prof.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "fileutils"
4
+ require "logger"
5
+
4
6
  require "test_prof/version"
5
7
  require "test_prof/logging"
6
8
  require "test_prof/utils"
@@ -44,6 +46,13 @@ module TestProf
44
46
  defined?(Minitest)
45
47
  end
46
48
 
49
+ # Returns true if Spring is used and not disabled
50
+ def spring?
51
+ # See https://github.com/rails/spring/blob/577cf01f232bb6dbd0ade7df2df2ac209697e741/lib/spring/binstub.rb
52
+ disabled = ENV["DISABLE_SPRING"]
53
+ defined?(::Spring::Application) && (disabled.nil? || disabled.empty? || disabled == "0")
54
+ end
55
+
47
56
  # Returns the current process time
48
57
  def now
49
58
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
@@ -63,7 +72,7 @@ module TestProf
63
72
  # equal to the provided value (if any).
64
73
  # Contains workaround for applications using Spring.
65
74
  def activate(env_var, val = nil)
66
- if defined?(::Spring::Application)
75
+ if spring?
67
76
  notify_spring_detected
68
77
  ::Spring.after_fork do
69
78
  activate!(env_var, val) do
@@ -130,7 +139,7 @@ module TestProf
130
139
 
131
140
  # TestProf configuration
132
141
  class Configuration
133
- attr_accessor :output, # IO to write output messages.
142
+ attr_accessor :output, # IO to write logs
134
143
  :color, # Whether to colorize output or not
135
144
  :output_dir, # Directory to store artifacts
136
145
  :timestamps, # Whether to use timestamped names for artifacts,
@@ -145,12 +154,16 @@ module TestProf
145
154
  end
146
155
 
147
156
  def color?
148
- color == true
157
+ color == true && output.is_a?(IO) && output.tty?
149
158
  end
150
159
 
151
160
  def timestamps?
152
161
  timestamps == true
153
162
  end
163
+
164
+ def logger
165
+ @logger ||= Logger.new(output, formatter: Logging::Formatter.new)
166
+ end
154
167
  end
155
168
  end
156
169
 
@@ -161,5 +174,5 @@ require "test_prof/factory_doctor"
161
174
  require "test_prof/factory_prof"
162
175
  require "test_prof/rspec_stamp"
163
176
  require "test_prof/tag_prof"
164
- require "test_prof/rspec_dissect"
177
+ require "test_prof/rspec_dissect" if TestProf.rspec?
165
178
  require "test_prof/factory_all_stub"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-17 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,6 +119,7 @@ files:
119
119
  - assets/tagprof.demo.html
120
120
  - assets/tagprof.template.html
121
121
  - config/default.yml
122
+ - config/rubocop-rspec.yml
122
123
  - lib/minitest/base_reporter.rb
123
124
  - lib/minitest/event_prof_formatter.rb
124
125
  - lib/minitest/test_prof_plugin.rb
@@ -126,6 +127,11 @@ files:
126
127
  - lib/test_prof.rb
127
128
  - lib/test_prof/any_fixture.rb
128
129
  - lib/test_prof/any_fixture/dsl.rb
130
+ - lib/test_prof/any_fixture/dump.rb
131
+ - lib/test_prof/any_fixture/dump/base_adapter.rb
132
+ - lib/test_prof/any_fixture/dump/digest.rb
133
+ - lib/test_prof/any_fixture/dump/postgresql.rb
134
+ - lib/test_prof/any_fixture/dump/sqlite.rb
129
135
  - lib/test_prof/before_all.rb
130
136
  - lib/test_prof/before_all/adapters/active_record.rb
131
137
  - lib/test_prof/before_all/isolator.rb
@@ -136,7 +142,6 @@ files:
136
142
  - lib/test_prof/cops/rspec/aggregate_examples/matchers_with_side_effects.rb
137
143
  - lib/test_prof/cops/rspec/aggregate_examples/metadata_helpers.rb
138
144
  - lib/test_prof/cops/rspec/aggregate_examples/node_matchers.rb
139
- - lib/test_prof/cops/rspec/aggregate_failures.rb
140
145
  - lib/test_prof/cops/rspec/language.rb
141
146
  - lib/test_prof/event_prof.rb
142
147
  - lib/test_prof/event_prof/custom_events.rb
@@ -148,7 +153,6 @@ files:
148
153
  - lib/test_prof/event_prof/monitor.rb
149
154
  - lib/test_prof/event_prof/profiler.rb
150
155
  - lib/test_prof/event_prof/rspec.rb
151
- - lib/test_prof/ext/active_record_3.rb
152
156
  - lib/test_prof/ext/active_record_refind.rb
153
157
  - lib/test_prof/ext/array_bsearch_index.rb
154
158
  - lib/test_prof/ext/factory_bot_strategy.rb
@@ -170,11 +174,11 @@ files:
170
174
  - lib/test_prof/factory_prof/factory_bot_patch.rb
171
175
  - lib/test_prof/factory_prof/factory_builders/fabrication.rb
172
176
  - lib/test_prof/factory_prof/factory_builders/factory_bot.rb
177
+ - lib/test_prof/factory_prof/nate_heckler.rb
173
178
  - lib/test_prof/factory_prof/printers/flamegraph.rb
179
+ - lib/test_prof/factory_prof/printers/nate_heckler.rb
174
180
  - lib/test_prof/factory_prof/printers/simple.rb
175
181
  - lib/test_prof/logging.rb
176
- - lib/test_prof/recipes/active_record_one_love.rb
177
- - lib/test_prof/recipes/active_record_shared_connection.rb
178
182
  - lib/test_prof/recipes/logging.rb
179
183
  - lib/test_prof/recipes/minitest/before_all.rb
180
184
  - lib/test_prof/recipes/minitest/sample.rb
@@ -208,16 +212,17 @@ files:
208
212
  - lib/test_prof/utils/rspec.rb
209
213
  - lib/test_prof/utils/sized_ordered_set.rb
210
214
  - lib/test_prof/version.rb
211
- homepage: http://github.com/palkan/test-prof
215
+ homepage: http://github.com/test-prof/test-prof
212
216
  licenses:
213
217
  - MIT
214
218
  metadata:
215
- bug_tracker_uri: http://github.com/palkan/test-prof/issues
216
- changelog_uri: https://github.com/palkan/test-prof/blob/master/CHANGELOG.md
219
+ bug_tracker_uri: https://github.com/test-prof/test-prof/issues
220
+ changelog_uri: https://github.com/test-prof/test-prof/blob/master/CHANGELOG.md
217
221
  documentation_uri: https://test-prof.evilmartians.io/
218
222
  homepage_uri: https://test-prof.evilmartians.io/
219
- source_code_uri: http://github.com/palkan/test-prof
220
- post_install_message:
223
+ source_code_uri: https://github.com/test-prof/test-prof
224
+ funding_uri: https://github.com/sponsors/test-prof
225
+ post_install_message:
221
226
  rdoc_options: []
222
227
  require_paths:
223
228
  - lib
@@ -232,8 +237,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
237
  - !ruby/object:Gem::Version
233
238
  version: '0'
234
239
  requirements: []
235
- rubygems_version: 3.0.6
236
- signing_key:
240
+ rubygems_version: 3.2.15
241
+ signing_key:
237
242
  specification_version: 4
238
243
  summary: Ruby applications tests profiling tools
239
244
  test_files: []
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- class AggregateExamples
7
- def self.registry
8
- RuboCop::Cop::Cop.registry
9
- end
10
- end
11
-
12
- class AggregateFailures < AggregateExamples
13
- def initialize(*)
14
- super
15
- self.class.just_once { warn "`AggregateFailures` cop has been renamed to `AggregateExamples`." }
16
- end
17
-
18
- def self.just_once
19
- return if @already_done
20
- yield
21
- @already_done = true
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module TestProf
4
- # Add missing `begin_transaction` and `rollback_transaction` methods
5
- module ActiveRecord3Transactions
6
- refine ::ActiveRecord::ConnectionAdapters::AbstractAdapter do
7
- def begin_transaction(joinable: true)
8
- increment_open_transactions
9
- if open_transactions > 0
10
- create_savepoint
11
- else
12
- begin_db_transaction
13
- end
14
- self.transaction_joinable = joinable
15
- end
16
-
17
- def rollback_transaction(*)
18
- if open_transactions > 1
19
- rollback_to_savepoint
20
- else
21
- rollback_db_transaction
22
- end
23
- decrement_open_transactions
24
- end
25
- end
26
- end
27
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "./active_record_shared_connection"
4
-
5
- # One ❤️
6
- TestProf::ActiveRecordOneLove = TestProf::ActiveRecordSharedConnection
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module TestProf
4
- # Forces ActiveRecord to use the same connection between threads
5
- module ActiveRecordSharedConnection # :nodoc: all
6
- class << self
7
- attr_reader :connection
8
-
9
- def enable!
10
- self.connection = ActiveRecord::Base.connection
11
- end
12
-
13
- def disable!
14
- self.connection = nil
15
- end
16
-
17
- def ignore(&block)
18
- raise ArgumentError, "Block is required" unless block_given?
19
-
20
- @ignores ||= []
21
-
22
- ignores << block
23
- end
24
-
25
- def ignored?(config)
26
- !ignores.nil? && ignores.any? { |clbk| clbk.call(config) }
27
- end
28
-
29
- private
30
-
31
- attr_reader :ignores
32
-
33
- def connection=(conn)
34
- @connection = conn
35
- connection.singleton_class.prepend Connection
36
- connection
37
- end
38
- end
39
-
40
- module Connection
41
- def shared_lock
42
- @shared_lock ||= Mutex.new
43
- end
44
-
45
- def exec_cache(*)
46
- shared_lock.synchronize { super }
47
- end
48
-
49
- def exec_no_cache(*)
50
- shared_lock.synchronize { super }
51
- end
52
-
53
- def execute(*)
54
- shared_lock.synchronize { super }
55
- end
56
- end
57
-
58
- module Ext
59
- def connection
60
- return super if ActiveRecordSharedConnection.ignored?(connection_config)
61
- ActiveRecordSharedConnection.connection || super
62
- end
63
- end
64
- end
65
- end
66
-
67
- ActiveSupport.on_load(:active_record) do
68
- if ::ActiveRecord::Base.connection.pool.respond_to?(:lock_thread=)
69
- TestProf.log :warn, "You activated ActiveRecordSharedConnection patch for the Rails version,\n" \
70
- "which has a built-in support for the same functionality.\n" \
71
- "Consider removing it, 'cause this could result in unexpected behaviour.\n\n" \
72
- "Read more in the docs: https://test-prof.evilmartians.io/#/active_record_shared_connection"
73
- end
74
-
75
- TestProf::ActiveRecordSharedConnection.enable!
76
- ActiveRecord::Base.singleton_class.prepend TestProf::ActiveRecordSharedConnection::Ext
77
- end