test-prof 0.1.0.pre5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +16 -4
  4. data/assets/flamegraph.demo.html +173 -0
  5. data/assets/flamegraph.template.html +196 -0
  6. data/assets/src/d3-tip.js +352 -0
  7. data/assets/src/d3-tip.min.js +1 -0
  8. data/assets/src/d3.flameGraph.css +92 -0
  9. data/assets/src/d3.flameGraph.js +459 -0
  10. data/assets/src/d3.flameGraph.min.css +1 -0
  11. data/assets/src/d3.flameGraph.min.js +1 -0
  12. data/assets/src/d3.v4.min.js +8 -0
  13. data/guides/any_fixture.md +1 -1
  14. data/guides/event_prof.md +30 -0
  15. data/guides/factory_default.md +109 -0
  16. data/guides/factory_prof.md +85 -0
  17. data/guides/rubocop.md +48 -0
  18. data/guides/ruby_prof.md +2 -0
  19. data/guides/stack_prof.md +5 -1
  20. data/guides/tag_prof.md +52 -0
  21. data/guides/tests_sampling.md +24 -0
  22. data/lib/test_prof.rb +31 -7
  23. data/lib/test_prof/cops/rspec/aggregate_failures.rb +140 -0
  24. data/lib/test_prof/event_prof/custom_events.rb +3 -3
  25. data/lib/test_prof/event_prof/custom_events/factory_create.rb +10 -8
  26. data/lib/test_prof/event_prof/custom_events/sidekiq_inline.rb +10 -8
  27. data/lib/test_prof/event_prof/custom_events/sidekiq_jobs.rb +12 -10
  28. data/lib/test_prof/event_prof/rspec.rb +5 -1
  29. data/lib/test_prof/factory_default.rb +58 -0
  30. data/lib/test_prof/factory_default/factory_girl_patch.rb +22 -0
  31. data/lib/test_prof/factory_doctor.rb +11 -9
  32. data/lib/test_prof/factory_doctor/rspec.rb +5 -3
  33. data/lib/test_prof/factory_prof.rb +140 -0
  34. data/lib/test_prof/factory_prof/factory_girl_patch.rb +12 -0
  35. data/lib/test_prof/factory_prof/printers/flamegraph.rb +71 -0
  36. data/lib/test_prof/factory_prof/printers/simple.rb +28 -0
  37. data/lib/test_prof/recipes/minitest/sample.rb +29 -0
  38. data/lib/test_prof/recipes/rspec/factory_default.rb +9 -0
  39. data/lib/test_prof/recipes/rspec/sample.rb +13 -0
  40. data/lib/test_prof/rspec_stamp/rspec.rb +5 -1
  41. data/lib/test_prof/rubocop.rb +3 -0
  42. data/lib/test_prof/ruby_prof.rb +6 -12
  43. data/lib/test_prof/stack_prof.rb +14 -7
  44. data/lib/test_prof/tag_prof.rb +8 -0
  45. data/lib/test_prof/tag_prof/rspec.rb +84 -0
  46. data/lib/test_prof/version.rb +1 -1
  47. metadata +48 -41
  48. data/.gitignore +0 -10
  49. data/.rspec +0 -2
  50. data/.rubocop.yml +0 -69
  51. data/.travis.yml +0 -5
  52. data/Gemfile +0 -4
  53. data/Rakefile +0 -8
  54. data/bin/setup +0 -8
  55. data/circle.yml +0 -11
  56. data/spec/integrations/any_fixture_spec.rb +0 -11
  57. data/spec/integrations/before_all_spec.rb +0 -11
  58. data/spec/integrations/event_prof_spec.rb +0 -100
  59. data/spec/integrations/factory_doctor_spec.rb +0 -20
  60. data/spec/integrations/fixtures/rspec/any_fixture_fixture.rb +0 -37
  61. data/spec/integrations/fixtures/rspec/before_all_fixture.rb +0 -32
  62. data/spec/integrations/fixtures/rspec/event_prof_factory_create_fixture.rb +0 -23
  63. data/spec/integrations/fixtures/rspec/event_prof_fixture.rb +0 -51
  64. data/spec/integrations/fixtures/rspec/event_prof_sidekiq_fixture.rb +0 -53
  65. data/spec/integrations/fixtures/rspec/factory_doctor_fixture.rb +0 -33
  66. data/spec/integrations/fixtures/rspec/rspec_stamp_fixture_tmpl.rb +0 -33
  67. data/spec/integrations/rspec_stamp_spec.rb +0 -53
  68. data/spec/spec_helper.rb +0 -38
  69. data/spec/support/ar_models.rb +0 -43
  70. data/spec/support/instrumenter_stub.rb +0 -19
  71. data/spec/support/integration_helpers.rb +0 -13
  72. data/spec/support/transactional_context.rb +0 -11
  73. data/spec/test_prof/any_fixture_spec.rb +0 -66
  74. data/spec/test_prof/event_prof_spec.rb +0 -138
  75. data/spec/test_prof/ext/float_duration_spec.rb +0 -12
  76. data/spec/test_prof/factory_doctor_spec.rb +0 -84
  77. data/spec/test_prof/rspec_stamp/parser_spec.rb +0 -58
  78. data/spec/test_prof/rspec_stamp_spec.rb +0 -281
  79. data/spec/test_prof/ruby_prof_spec.rb +0 -109
  80. data/spec/test_prof/stack_prof_spec.rb +0 -73
  81. data/spec/test_prof_spec.rb +0 -23
  82. data/test-prof.gemspec +0 -35
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.gem
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.rubocop.yml DELETED
@@ -1,69 +0,0 @@
1
- AllCops:
2
- Include:
3
- - 'lib/**/*.rb'
4
- - 'lib/**/*.rake'
5
- - 'spec/**/*.rb'
6
- Exclude:
7
- - 'bin/**/*'
8
- - 'spec/dummy/**/*'
9
- - 'tmp/**/*'
10
- - 'Rakefile'
11
- - 'Gemfile'
12
- - '*.gemspec'
13
- DisplayCopNames: true
14
- StyleGuideCopsOnly: false
15
- TargetRubyVersion: 2.3
16
-
17
- Rails:
18
- Enabled: false
19
-
20
- Style/AccessorMethodName:
21
- Enabled: false
22
-
23
- Style/TrivialAccessors:
24
- Enabled: false
25
-
26
- Style/Documentation:
27
- Exclude:
28
- - 'spec/**/*.rb'
29
-
30
- Style/StringLiterals:
31
- Enabled: false
32
-
33
- Style/RegexpLiteral:
34
- Enabled: false
35
-
36
- Style/SpaceInsideStringInterpolation:
37
- EnforcedStyle: no_space
38
-
39
- Style/ClassAndModuleChildren:
40
- Enabled: false
41
-
42
- Style/BlockDelimiters:
43
- Exclude:
44
- - 'spec/**/*.rb'
45
-
46
- Lint/AmbiguousRegexpLiteral:
47
- Enabled: false
48
-
49
-
50
- Metrics/MethodLength:
51
- Enabled: false
52
-
53
- Metrics/AbcSize:
54
- Enabled: false
55
-
56
- Metrics/LineLength:
57
- Max: 100
58
- Exclude:
59
- - 'spec/**/*.rb'
60
-
61
- Metrics/BlockLength:
62
- Exclude:
63
- - 'spec/**/*.rb'
64
-
65
- Rails/Date:
66
- Enabled: false
67
-
68
- Rails/TimeZone:
69
- Enabled: false
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.3
5
- before_install: gem install bundler -v 1.13.6
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in test-prof.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
- require "rubocop/rake_task"
4
-
5
- RSpec::Core::RakeTask.new(:spec)
6
- RuboCop::RakeTask.new
7
-
8
- task :default => [:spec, :rubocop]
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/circle.yml DELETED
@@ -1,11 +0,0 @@
1
- machine:
2
- ruby:
3
- version: 2.4.1
4
-
5
- database:
6
- override:
7
- - echo "Skipping DB section."
8
-
9
- dependencies:
10
- pre:
11
- - gem install bundler -v 1.13.6
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe "AnyFixture" do
6
- specify "it works" do
7
- output = run_rspec('any_fixture')
8
-
9
- expect(output).to include("3 examples, 0 failures")
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe "BeforeAll" do
6
- specify "it works" do
7
- output = run_rspec('before_all')
8
-
9
- expect(output).to include("3 examples, 0 failures")
10
- end
11
- end
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe "EventProf" do
6
- specify "RSpec integration", :aggregate_failures do
7
- output = run_rspec('event_prof', env: { 'EVENT_PROF' => 'test.event' })
8
-
9
- expect(output).to include("EventProf results for test.event")
10
- expect(output).to match(/Total time: 25:56\.\d{3}/)
11
- expect(output).to include("Total events: 8")
12
-
13
- expect(output).to include("Top 5 slowest suites (by time):")
14
- expect(output).to include("Top 5 slowest tests (by time):")
15
-
16
- expect(output).to include(
17
- "Another something (./event_prof_fixture.rb:42) – 16:40.000 (1 / 2)\n"\
18
- "Something (./event_prof_fixture.rb:21) – 09:16.100 (7 / 3)"
19
- )
20
-
21
- expect(output).to include(
22
- "do very long (./event_prof_fixture.rb:47) – 16:40.000 (1)\n"\
23
- "invokes twice (./event_prof_fixture.rb:27) – 06:20.000 (2)\n"\
24
- "invokes many times (./event_prof_fixture.rb:33) – 02:16.000 (4)\n"\
25
- "invokes once (./event_prof_fixture.rb:22) – 00:40.100 (1)"
26
- )
27
- end
28
-
29
- specify "RSpec integration with rank by count", :aggregate_failures do
30
- output = run_rspec(
31
- 'event_prof',
32
- env: { 'EVENT_PROF' => 'test.event', 'EVENT_PROF_RANK' => 'count' }
33
- )
34
-
35
- expect(output).to include("EventProf results for test.event")
36
- expect(output).to match(/Total time: 25:56\.\d{3}/)
37
- expect(output).to include("Total events: 8")
38
-
39
- expect(output).to include("Top 5 slowest suites (by count):")
40
- expect(output).to include("Top 5 slowest tests (by count):")
41
-
42
- expect(output).to include(
43
- "Something (./event_prof_fixture.rb:21) – 09:16.100 (7 / 3)\n"\
44
- "Another something (./event_prof_fixture.rb:42) – 16:40.000 (1 / 2)"
45
- )
46
-
47
- expect(output).to include(
48
- "invokes many times (./event_prof_fixture.rb:33) – 02:16.000 (4)\n"\
49
- "invokes twice (./event_prof_fixture.rb:27) – 06:20.000 (2)\n"\
50
- "invokes once (./event_prof_fixture.rb:22) – 00:40.100 (1)\n"\
51
- "do very long (./event_prof_fixture.rb:47) – 16:40.000 (1)"
52
- )
53
- end
54
-
55
- context "CustomEvents" do
56
- it "works with factory.create" do
57
- output = run_rspec(
58
- 'event_prof_factory_create',
59
- env: { 'EVENT_PROF' => 'factory.create' }
60
- )
61
-
62
- expect(output).to include("EventProf results for factory.create")
63
- expect(output).to match(/Total time: \d{2}:\d{2}\.\d{3}/)
64
- expect(output).to include("Total events: 3")
65
-
66
- expect(output).to match(%r{Post \(./event_prof_factory_create_fixture.rb:7\) – \d{2}:\d{2}.\d{3} \(2 / 1\)})
67
- expect(output).to match(%r{User \(./event_prof_factory_create_fixture.rb:16\) – \d{2}:\d{2}.\d{3} \(1 / 1\)})
68
- end
69
-
70
- it "works with sidekiq.inline" do
71
- output = run_rspec(
72
- 'event_prof_sidekiq',
73
- env: { 'EVENT_PROF' => 'sidekiq.inline' }
74
- )
75
-
76
- expect(output).to include("EventProf results for sidekiq.inline")
77
- expect(output).to match(/Total time: \d{2}:\d{2}\.\d{3}/)
78
- expect(output).to include("Total events: 3")
79
-
80
- expect(output).to match(%r{SingleJob \(./event_prof_sidekiq_fixture.rb:27\) – \d{2}:\d{2}.\d{3} \(2 / 2\)})
81
- expect(output).to match(%r{BatchJob \(./event_prof_sidekiq_fixture.rb:39\) – \d{2}:\d{2}.\d{3} \(1 / 2\)})
82
- end
83
-
84
- it "works with sidekiq.jobs" do
85
- output = run_rspec(
86
- 'event_prof_sidekiq',
87
- env: { 'EVENT_PROF' => 'sidekiq.jobs' }
88
- )
89
-
90
- expect(output).to include("EventProf results for sidekiq.jobs")
91
- expect(output).to match(/Total time: \d{2}:\d{2}\.\d{3}/)
92
- expect(output).to include("Total events: 6")
93
-
94
- expect(output).to include("Top 5 slowest suites (by count):")
95
-
96
- expect(output).to match(%r{SingleJob \(./event_prof_sidekiq_fixture.rb:27\) – \d{2}:\d{2}.\d{3} \(2 / 2\)})
97
- expect(output).to match(%r{BatchJob \(./event_prof_sidekiq_fixture.rb:39\) – \d{2}:\d{2}.\d{3} \(4 / 2\)})
98
- end
99
- end
100
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe "FactoryDoctor" do
6
- specify "RSpec integration", :aggregate_failures do
7
- output = run_rspec('factory_doctor', env: { 'FDOC' => '1' })
8
-
9
- expect(output).to include("FactoryDoctor report")
10
- expect(output).to include("Total (potentially) bad examples: 3")
11
- expect(output).to match(/Total wasted time: \d{2}:\d{2}\.\d{3}/)
12
-
13
- expect(output).to include("User (./factory_doctor_fixture.rb:7)")
14
- expect(output).to include("generates random names (./factory_doctor_fixture.rb:10) – 2 records created")
15
- expect(output).to include("validates name (./factory_doctor_fixture.rb:15) – 1 record created")
16
- expect(output).to include("clones (./factory_doctor_fixture.rb:25) – 1 record created")
17
- expect(output).not_to include("is ignored")
18
- expect(output).not_to include("creates and reloads user")
19
- end
20
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
4
- require_relative "../../../support/ar_models"
5
- require_relative "../../../support/transactional_context"
6
- require "test_prof/recipes/rspec/any_fixture"
7
-
8
- shared_context "user", user: true do
9
- before(:all) do
10
- @user = TestProf::AnyFixture.register(:user) do
11
- FactoryGirl.create(:user)
12
- end
13
- end
14
-
15
- let(:user) { User.find(@user.id) }
16
- end
17
-
18
- describe "User", :user do
19
- it "creates user" do
20
- user.name = ''
21
- expect(user).not_to be_valid
22
- end
23
-
24
- context "with clean fixture", :transactional, :with_clean_fixture do
25
- specify "no users" do
26
- expect(User.count).to eq 0
27
- end
28
- end
29
- end
30
-
31
- describe "Post", :user do
32
- let(:post) { FactoryGirl.create(:post, user: user) }
33
-
34
- it "creates post with the same user" do
35
- expect { post }.not_to change(User, :count)
36
- end
37
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
4
- require_relative "../../../support/ar_models"
5
- require "test_prof/recipes/rspec/before_all"
6
-
7
- describe "User" do
8
- context "with before_all" do
9
- before_all do
10
- @user = FactoryGirl.create(:user)
11
- end
12
-
13
- let(:user) { User.find(@user.id) }
14
-
15
- it "validates name" do
16
- user.name = ''
17
- expect(user).not_to be_valid
18
- end
19
-
20
- it "clones" do
21
- cloned = user.clone
22
- cloned.save!
23
- expect(cloned.reload.name).to include("(cloned)")
24
- end
25
- end
26
-
27
- context "without before_all" do
28
- specify "no users" do
29
- expect(User.count).to eq 0
30
- end
31
- end
32
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
4
- require_relative "../../../support/ar_models"
5
- require "test-prof"
6
-
7
- describe "Post" do
8
- let(:user) { FactoryGirl.create(:user) }
9
-
10
- it "generates random names" do
11
- user2 = FactoryGirl.create(:post).user
12
- expect(user.name).not_to eq user2.name
13
- end
14
- end
15
-
16
- describe "User" do
17
- let(:user) { FactoryGirl.create(:user) }
18
-
19
- it "validates name" do
20
- user.name = ''
21
- expect(user).not_to be_valid
22
- end
23
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
4
- require "active_support"
5
- require "test-prof"
6
-
7
- TestProf::EventProf.configure do |config|
8
- config.per_example = true
9
- end
10
-
11
- module Instrumenter
12
- def self.notify(_event, time)
13
- ActiveSupport::Notifications.publish(
14
- 'test.event',
15
- 0,
16
- time
17
- )
18
- end
19
- end
20
-
21
- describe "Something" do
22
- it "invokes once" do
23
- Instrumenter.notify 'test.event', 40.1
24
- expect(true).to eq true
25
- end
26
-
27
- it "invokes twice" do
28
- Instrumenter.notify 'test.event', 140
29
- Instrumenter.notify 'test.event', 240
30
- expect(true).to eq true
31
- end
32
-
33
- it "invokes many times" do
34
- Instrumenter.notify 'test.event', 14
35
- Instrumenter.notify 'test.event', 40
36
- Instrumenter.notify 'test.event', 42
37
- Instrumenter.notify 'test.event', 40
38
- expect(true).to eq true
39
- end
40
- end
41
-
42
- describe "Another something" do
43
- it "do nothing" do
44
- expect(true).to eq true
45
- end
46
-
47
- it "do very long" do
48
- Instrumenter.notify 'test.event', 1000
49
- expect(true).to eq true
50
- end
51
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
4
- require "active_support"
5
- require "sidekiq/testing"
6
-
7
- Sidekiq::Testing.inline!
8
-
9
- class SingleJob
10
- include Sidekiq::Worker
11
-
12
- def perform(*_args)
13
- true
14
- end
15
- end
16
-
17
- class BatchJob
18
- include Sidekiq::Worker
19
-
20
- def perform(count)
21
- count.times { SingleJob.perform_async(true) }
22
- end
23
- end
24
-
25
- require "test-prof"
26
-
27
- describe "SingleJob" do
28
- it "invokes once" do
29
- SingleJob.perform_async(1)
30
- expect(true).to eq true
31
- end
32
-
33
- it "invokes twice" do
34
- SingleJob.perform_async(2)
35
- expect(true).to eq true
36
- end
37
- end
38
-
39
- describe "BatchJob" do
40
- it "invokes nested" do
41
- BatchJob.perform_async(3)
42
- expect(true).to eq true
43
- end
44
-
45
- context "when fake" do
46
- it "is fake" do
47
- Sidekiq::Testing.fake! do
48
- BatchJob.perform_async(3)
49
- end
50
- expect(true).to eq true
51
- end
52
- end
53
- end