knapsack_pro 2.18.1 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -1
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +33 -0
  5. data/README.md +8 -3
  6. data/knapsack_pro.gemspec +1 -1
  7. data/lib/knapsack_pro/adapters/base_adapter.rb +4 -4
  8. data/lib/knapsack_pro/adapters/rspec_adapter.rb +5 -10
  9. data/lib/knapsack_pro/config/env.rb +8 -1
  10. data/lib/knapsack_pro/config/temp_files.rb +38 -0
  11. data/lib/knapsack_pro/report.rb +7 -8
  12. data/lib/knapsack_pro/runners/cucumber_runner.rb +3 -0
  13. data/lib/knapsack_pro/runners/minitest_runner.rb +3 -0
  14. data/lib/knapsack_pro/runners/queue/cucumber_runner.rb +3 -1
  15. data/lib/knapsack_pro/runners/queue/minitest_runner.rb +3 -1
  16. data/lib/knapsack_pro/runners/queue/rspec_runner.rb +3 -2
  17. data/lib/knapsack_pro/runners/rspec_runner.rb +3 -0
  18. data/lib/knapsack_pro/runners/spinach_runner.rb +3 -0
  19. data/lib/knapsack_pro/runners/test_unit_runner.rb +3 -0
  20. data/lib/knapsack_pro/slow_test_file_determiner.rb +8 -4
  21. data/lib/knapsack_pro/test_case_detectors/rspec_test_example_detector.rb +9 -6
  22. data/lib/knapsack_pro/tracker.rb +56 -1
  23. data/lib/knapsack_pro/version.rb +1 -1
  24. data/lib/knapsack_pro.rb +1 -0
  25. data/spec/knapsack_pro/adapters/base_adapter_spec.rb +9 -7
  26. data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +20 -24
  27. data/spec/knapsack_pro/config/env_spec.rb +25 -0
  28. data/spec/knapsack_pro/config/temp_files_spec.rb +25 -0
  29. data/spec/knapsack_pro/report_spec.rb +11 -10
  30. data/spec/knapsack_pro/runners/cucumber_runner_spec.rb +9 -1
  31. data/spec/knapsack_pro/runners/minitest_runner_spec.rb +6 -1
  32. data/spec/knapsack_pro/runners/queue/cucumber_runner_spec.rb +2 -0
  33. data/spec/knapsack_pro/runners/queue/minitest_runner_spec.rb +2 -0
  34. data/spec/knapsack_pro/runners/queue/rspec_runner_spec.rb +2 -0
  35. data/spec/knapsack_pro/runners/rspec_runner_spec.rb +9 -1
  36. data/spec/knapsack_pro/runners/spinach_runner_spec.rb +9 -1
  37. data/spec/knapsack_pro/runners/test_unit_runner_spec.rb +6 -1
  38. data/spec/knapsack_pro/slow_test_file_determiner_spec.rb +2 -2
  39. data/spec/knapsack_pro/test_case_detectors/rspec_test_example_detector_spec.rb +8 -6
  40. data/spec/knapsack_pro/tracker_spec.rb +67 -2
  41. data/spec/spec_helper.rb +5 -2
  42. metadata +6 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfa70d9f5566c820f5ca45bc6c0dc52302ee7de056f4b50ad86739b3ca34960d
4
- data.tar.gz: a5c877f7c89a4c94bbcd247a6fe75b8ff01a9e2be7f82b82fe4ac42dcdac489c
3
+ metadata.gz: 1a66b28a9f7bdfa3aaa0492c3099b62d020b2a01a48030865c503448ccb4ff77
4
+ data.tar.gz: c0fae2955b72521decd338c64be57c31eacc2f33d41dbce39610be0584183aab
5
5
  SHA512:
6
- metadata.gz: 390be4aa9a3bfa79da3149bbc7acdec09905aed17ddbac32998e7324cc23571bcb321e3ba541d3890df1993ab5a125c10edf5cfcf28f8568347ff96af8b18a94
7
- data.tar.gz: 431ec87a1b9c17fb9e2c5dfde14d93118e0378731f6c70ff7fcb1ed4f74dcef773bd861be33d0d4327689d4d8fb9df333df59630f44c9be3212b3915f2ab5cd4
6
+ metadata.gz: c142d923945cb4ed649535b93d0a632f5ed705513c9b3528e776784e0f6e5959ce08b81c084e69a89dd42027e453f32c2830743e8f366afe2d0fb4ddca5d8ae7
7
+ data.tar.gz: 6ca8aa6ac8ad655bb267e17ba93564b5f44585b0dcaac74e195c7e818323f9aa954da067753c7c0b9b7c3782d3d3ecbf2e3829e7c147a9f054cde3af56898ad8
data/.circleci/config.yml CHANGED
@@ -8,7 +8,7 @@ jobs:
8
8
  parallelism: 1
9
9
  docker:
10
10
  # specify the version you desire here
11
- - image: circleci/ruby:3.0.1
11
+ - image: circleci/ruby:3.0.2
12
12
  environment:
13
13
  CODECLIMATE_REPO_TOKEN: b6626e682a8e97e0c5978febc92c3526792a2d018b41b8e1b52689da37fb7d92
14
14
 
data/.gitignore CHANGED
@@ -8,6 +8,7 @@
8
8
  /test/tmp/
9
9
  /test/version_tmp/
10
10
  /tmp/
11
+ .knapsack_pro
11
12
 
12
13
  ## Specific to RubyMotion:
13
14
  .dat*
data/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Change Log
2
2
 
3
+ ### 3.1.1
4
+
5
+ * Rephrase log outputs in the Queue Mode RSpec runner
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/160
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v3.1.0...v3.1.1
10
+
11
+ ### 3.1.0
12
+
13
+ * Use `.knapsack_pro` directory for temporary files instead of the `tmp` directory in the user's project directory
14
+
15
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/155
16
+
17
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v3.0.0...v3.1.0
18
+
19
+ ### 3.0.0
20
+
21
+ * __(breaking change)__ Remove support for RSpec 2.x. This change was already done by accident in [the pull request](https://github.com/KnapsackPro/knapsack_pro-ruby/pull/143) when we added the RSpec `context` hook, which is available only since RSpec 3.x.
22
+ * Use RSpec `example` block argument instead of the global `RSpec.current_example`. This allows to run tests with the `async-rspec` gem.
23
+
24
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/153
25
+
26
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.18.2...v3.0.0
27
+
28
+ ### 2.18.2
29
+
30
+ * Track all test files assigned to a CI node in Regular Mode including pending test files in order to retry proper set of tests on the retried CI node
31
+
32
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/152
33
+
34
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.18.1...v2.18.2
35
+
3
36
  ### 2.18.1
4
37
 
5
38
  * Ensure RSpec is loaded to check its version for RSpec split by test examples feature
data/README.md CHANGED
@@ -440,13 +440,13 @@ If your test suite is very long and the RSpec output is too long for your CI nod
440
440
  ### Additional info about queue mode
441
441
 
442
442
  * You should use a separate API token for queue mode than for regular mode to avoid problems with test suite split (especially in case you would like to go back to regular mode).
443
- There might be some cached test suite splits for git commits you have run in past for API token you used in queue mode because of the [flag `KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=true` for regular mode which is default](#knapsack_pro_fixed_test_suite_splite-test-suite-split-based-on-seed).
443
+ There might be some cached test suite splits for git commits you have run in past for API token you used in queue mode because of the [flag `KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=true` for regular mode which is default](#knapsack_pro_fixed_test_suite_split-test-suite-split-based-on-seed).
444
444
 
445
445
  * If you are not using one of the [supported CI providers](#supported-ci-providers) then please note that the knapsack_pro gem doesn't have a CI build ID in order to generate a queue for each particular CI build. This may result in two different CI builds taking tests from the same queue when CI builds are running at the same time against the same git commit.
446
446
 
447
447
  To avoid this you should specify a unique `KNAPSACK_PRO_CI_NODE_BUILD_ID` environment variable for each CI build. This mean that each CI node that is part of particular CI build should have the same value for `KNAPSACK_PRO_CI_NODE_BUILD_ID`.
448
448
 
449
- * Note that in the Queue Mode by default you cannot retry the failed CI node with exactly the same subset of tests that were run on the CI node in the first place. It's possible in regular mode ([read more](#knapsack_pro_fixed_test_suite_splite-test-suite-split-based-on-seed)). If you want to have similar behavior in Queue Mode you need to explicitly [enable it](#knapsack_pro_fixed_queue_split-remember-queue-split-on-retry-ci-node).
449
+ * Note that in the Queue Mode by default you cannot retry the failed CI node with exactly the same subset of tests that were run on the CI node in the first place. It's possible in regular mode ([read more](#knapsack_pro_fixed_test_suite_split-test-suite-split-based-on-seed)). If you want to have similar behavior in Queue Mode you need to explicitly [enable it](#knapsack_pro_fixed_queue_split-remember-queue-split-on-retry-ci-node).
450
450
 
451
451
  By default the Queue Mode works this way:
452
452
 
@@ -626,7 +626,7 @@ This is only for maintainer of knapsack_pro gem. Not for the end users.
626
626
 
627
627
  ### Required CI configuration if you use retry single failed CI node feature on your CI server when KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true (in Queue Mode) or KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=true (in Regular Mode)
628
628
 
629
- Read below required configuration step if you use Queue Mode and you set [`KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true`](#knapsack_pro_fixed_queue_split-remember-queue-split-on-retry-ci-node) or you use Regular Mode which has by default [`KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=true`](#knapsack_pro_fixed_test_suite_splite-test-suite-split-based-on-seed).
629
+ Read below required configuration step if you use Queue Mode and you set [`KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true`](#knapsack_pro_fixed_queue_split-remember-queue-split-on-retry-ci-node) or you use Regular Mode which has by default [`KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=true`](#knapsack_pro_fixed_test_suite_split-test-suite-split-based-on-seed).
630
630
 
631
631
  * __IMPORTANT:__ If you use __the feature to retry only a single failed CI node__ on your CI server (for instance you use Buildkite and you use [auto-retry](https://buildkite.com/docs/pipelines/command-step#retry-attributes) for the failed job) then you need to be aware of [a race condition that could happen](https://github.com/KnapsackPro/knapsack_pro-ruby/pull/100). knapsack_pro should not allow running tests in Fallback Mode in the case when the failed CI node was retried to prevent running the wrong set of tests.
632
632
 
@@ -1714,6 +1714,11 @@ $ gem push knapsack_pro-X.X.X.gem
1714
1714
 
1715
1715
  Update the latest available gem version in `TestSuiteClientVersionChecker` for the Knapsack Pro API repository.
1716
1716
 
1717
+ Update knapsack_pro gem version in:
1718
+
1719
+ * https://github.com/KnapsackPro/rails-app-with-knapsack_pro
1720
+ * our private Knapsack Pro API repository
1721
+
1717
1722
  ## Mentions
1718
1723
 
1719
1724
  List of articles where people mentioned Knapsack Pro:
data/knapsack_pro.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency 'rake', '>= 0'
29
29
 
30
30
  spec.add_development_dependency 'bundler', '>= 1.6'
31
- spec.add_development_dependency 'rspec', '~> 3.0', '>= 2.10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
32
  spec.add_development_dependency 'rspec-its', '~> 1.3'
33
33
  spec.add_development_dependency 'cucumber', '>= 0'
34
34
  spec.add_development_dependency 'spinach', '>= 0.8'
@@ -6,7 +6,7 @@ module KnapsackPro
6
6
 
7
7
  def self.adapter_bind_method_called_file
8
8
  adapter_name = self.to_s.gsub('::', '-')
9
- "#{KnapsackPro::Config::Env::TMP_DIR}/#{adapter_name}-bind_method_called_for_node_#{KnapsackPro::Config::Env.ci_node_index}.txt"
9
+ "#{KnapsackPro::Config::TempFiles::TEMP_DIRECTORY_PATH}/#{adapter_name}-bind_method_called_for_node_#{KnapsackPro::Config::Env.ci_node_index}.txt"
10
10
  end
11
11
 
12
12
  def self.slow_test_file?(adapter_class, test_file_path)
@@ -33,20 +33,20 @@ module KnapsackPro
33
33
 
34
34
  def self.verify_bind_method_called
35
35
  ::Kernel.at_exit do
36
- if File.exists?(adapter_bind_method_called_file)
36
+ if File.exist?(adapter_bind_method_called_file)
37
37
  File.delete(adapter_bind_method_called_file)
38
38
  else
39
39
  puts "\n\n"
40
40
  KnapsackPro.logger.error('-'*10 + ' Configuration error ' + '-'*50)
41
41
  KnapsackPro.logger.error("You forgot to call #{self}.bind method in your test runner configuration file. It is needed to record test files time execution. Please follow the installation guide to configure your project properly https://docs.knapsackpro.com/knapsack_pro-ruby/guide/")
42
- KnapsackPro.logger.error("If you already have #{self}.bind method added and you still see this error then one of your tests must had to delete tmp/knapsack_pro directory from the disk accidentally. Please ensure you do not remove tmp/knapsack_pro directory: https://knapsackpro.com/faq/question/why-all-test-files-have-01s-time-execution-for-my-ci-build-in-user-dashboard")
42
+ KnapsackPro.logger.error("If you already have #{self}.bind method added and you still see this error then one of your tests must have deleted the .knapsack_pro directory from the disk accidentally. Please ensure you do not remove the .knapsack_pro directory: https://knapsackpro.com/faq/question/why-all-test-files-have-01s-time-execution-for-my-ci-build-in-user-dashboard")
43
43
  Kernel.exit(1)
44
44
  end
45
45
  end
46
46
  end
47
47
 
48
48
  def bind
49
- FileUtils.mkdir_p(KnapsackPro::Config::Env::TMP_DIR)
49
+ KnapsackPro::Config::TempFiles.ensure_temp_directory_exists!
50
50
  File.write(self.class.adapter_bind_method_called_file, nil)
51
51
 
52
52
  if KnapsackPro::Config::Env.recording_enabled?
@@ -24,8 +24,10 @@ module KnapsackPro
24
24
  cli_args.any? { |arg| arg.start_with?('-f') || arg.start_with?('--format') }
25
25
  end
26
26
 
27
- def self.test_path(example_group)
28
- if defined?(::Turnip) && ::Turnip::VERSION.to_i < 2
27
+ def self.test_path(example)
28
+ example_group = example.metadata[:example_group]
29
+
30
+ if defined?(::Turnip) && Gem::Version.new(::Turnip::VERSION) < Gem::Version.new('2.0.0')
29
31
  unless example_group[:turnip]
30
32
  until example_group[:parent_example_group].nil?
31
33
  example_group = example_group[:parent_example_group]
@@ -51,14 +53,7 @@ module KnapsackPro
51
53
  # this way we count time spend in runtime for the previous test example after around(:each) is already done
52
54
  KnapsackPro.tracker.stop_timer
53
55
 
54
- current_example_group =
55
- if ::RSpec.respond_to?(:current_example)
56
- ::RSpec.current_example.metadata[:example_group]
57
- else
58
- example.metadata
59
- end
60
-
61
- current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(current_example_group)
56
+ current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(example)
62
57
 
63
58
  KnapsackPro.tracker.current_test_path =
64
59
  if KnapsackPro::Config::Env.rspec_split_by_test_examples? && KnapsackPro::Adapters::RSpecAdapter.slow_test_file?(RSpecAdapter, current_test_path)
@@ -8,7 +8,6 @@ module KnapsackPro
8
8
  'info' => ::Logger::INFO,
9
9
  'debug' => ::Logger::DEBUG,
10
10
  }
11
- TMP_DIR = 'tmp/knapsack_pro'
12
11
 
13
12
  class << self
14
13
  def ci_node_total
@@ -257,6 +256,14 @@ module KnapsackPro
257
256
  ENV['KNAPSACK_PRO_LOG_DIR']
258
257
  end
259
258
 
259
+ def test_runner_adapter
260
+ ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER']
261
+ end
262
+
263
+ def set_test_runner_adapter(adapter_class)
264
+ ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER'] = adapter_class.to_s.split('::').last
265
+ end
266
+
260
267
  private
261
268
 
262
269
  def required_env(env_name)
@@ -0,0 +1,38 @@
1
+ module KnapsackPro
2
+ module Config
3
+ class TempFiles
4
+ # relative to the directory where you run knapsack_pro gem (user's project)
5
+ TEMP_DIRECTORY_PATH = '.knapsack_pro'
6
+
7
+ def self.ensure_temp_directory_exists!
8
+ unless File.exist?(gitignore_file_path)
9
+ create_temp_directory!
10
+ create_gitignore_file!
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def self.create_temp_directory!
17
+ FileUtils.mkdir_p(TEMP_DIRECTORY_PATH)
18
+ end
19
+
20
+ def self.gitignore_file_path
21
+ File.join(TEMP_DIRECTORY_PATH, '.gitignore')
22
+ end
23
+
24
+ def self.gitignore_file_content
25
+ "# This directory is used by knapsack_pro gem for storing temporary files during tests runtime.\n" <<
26
+ "# Ignore all files, and do not commit this directory into your repository.\n" <<
27
+ "# Learn more at https://knapsackpro.com\n" <<
28
+ "*"
29
+ end
30
+
31
+ def self.create_gitignore_file!
32
+ File.open(gitignore_file_path, 'w+') do |f|
33
+ f.write(gitignore_file_content)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -5,7 +5,7 @@ module KnapsackPro
5
5
 
6
6
  if test_files.empty?
7
7
  KnapsackPro.logger.warn("No test files were executed on this CI node.")
8
- KnapsackPro.logger.debug("When you use knapsack_pro regular mode then probably reason might be very narrowed tests list - you run only tests with specified tag and there are fewer test files with the tag than node total number.")
8
+ KnapsackPro.logger.debug("When you use knapsack_pro Regular Mode, the reason for no tests executing might be a very narrow tests list. Most likely, you run only tests with a specified tag, and there were fewer test files with the tag than parallel CI nodes.")
9
9
  end
10
10
 
11
11
  create_build_subset(test_files)
@@ -16,6 +16,7 @@ module KnapsackPro
16
16
 
17
17
  subset_queue_id = KnapsackPro::Config::Env.subset_queue_id
18
18
 
19
+ KnapsackPro::Config::TempFiles.ensure_temp_directory_exists!
19
20
  FileUtils.mkdir_p(queue_path)
20
21
 
21
22
  subset_queue_file_name = "#{subset_queue_id}.json"
@@ -36,8 +37,7 @@ module KnapsackPro
36
37
 
37
38
  if test_files.empty?
38
39
  KnapsackPro.logger.warn("No test files were executed on this CI node.")
39
- KnapsackPro.logger.debug("When you use knapsack_pro queue mode then probably reason might be that CI node was started after the test files from the queue were already executed by other CI nodes. That is why this CI node has no test files to execute.")
40
- KnapsackPro.logger.debug("Another reason might be when your CI node failed in a way that prevented knapsack_pro to save time execution data to Knapsack Pro API and you have just tried to retry failed CI node but instead you got no test files to execute. In that case knapsack_pro don't know what tests should be executed here.")
40
+ KnapsackPro.logger.debug("This CI node likely started work late after the test files were already executed by other CI nodes consuming the queue.")
41
41
  end
42
42
 
43
43
  measured_test_files = test_files
@@ -46,9 +46,9 @@ module KnapsackPro
46
46
 
47
47
  if test_files.size > 0 && measured_test_files.size == 0
48
48
  KnapsackPro.logger.warn("#{test_files.size} test files were executed on this CI node but the recorded time was lost due to:")
49
- KnapsackPro.logger.warn("1. Probably you have a code (i.e. RSpec hooks) that clears tmp directory in your project. Please ensure you do not remove the content of tmp/knapsack_pro/queue/ directory between tests run.")
50
- KnapsackPro.logger.warn("2. Another reason might be that you forgot to add Knapsack::Adapters::RSpecAdapter.bind in your rails_helper.rb or spec_helper.rb. Please follow the installation guide again: https://docs.knapsackpro.com/integration/")
51
- KnapsackPro.logger.warn("3. All your tests are empty test files, are pending tests or have syntax error and could not be executed hence no measured time execution by knapsack_pro.")
49
+ KnapsackPro.logger.warn("1. Please ensure you do not remove the contents of the .knapsack_pro directory between tests run.")
50
+ KnapsackPro.logger.warn("2. Ensure you've added Knapsack::Adapters::RSpecAdapter.bind in your rails_helper.rb or spec_helper.rb. Please follow the installation guide again: https://docs.knapsackpro.com/integration/")
51
+ KnapsackPro.logger.warn("3. Another potential reason for this warning is that all your tests are empty test files, pending tests, or they have syntax errors, and the time execution was not recorded for them.")
52
52
  end
53
53
 
54
54
  create_build_subset(test_files)
@@ -79,8 +79,7 @@ module KnapsackPro
79
79
  private
80
80
 
81
81
  def self.queue_path
82
- queue_id = KnapsackPro::Config::Env.queue_id
83
- "#{KnapsackPro::Config::Env::TMP_DIR}/queue/#{queue_id}"
82
+ "#{KnapsackPro::Config::TempFiles::TEMP_DIRECTORY_PATH}/queue/#{KnapsackPro::Config::Env.queue_id}"
84
83
  end
85
84
  end
86
85
  end
@@ -6,11 +6,14 @@ module KnapsackPro
6
6
  ENV['KNAPSACK_PRO_RECORDING_ENABLED'] = 'true'
7
7
 
8
8
  adapter_class = KnapsackPro::Adapters::CucumberAdapter
9
+ KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
9
10
  runner = new(adapter_class)
10
11
 
11
12
  if runner.test_files_to_execute_exist?
12
13
  adapter_class.verify_bind_method_called
13
14
 
15
+ KnapsackPro.tracker.set_prerun_tests(runner.test_file_paths)
16
+
14
17
  require 'cucumber/rake/task'
15
18
 
16
19
  task_name = 'knapsack_pro:cucumber_run'
@@ -6,11 +6,14 @@ module KnapsackPro
6
6
  ENV['KNAPSACK_PRO_RECORDING_ENABLED'] = 'true'
7
7
 
8
8
  adapter_class = KnapsackPro::Adapters::MinitestAdapter
9
+ KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
9
10
  runner = new(adapter_class)
10
11
 
11
12
  if runner.test_files_to_execute_exist?
12
13
  adapter_class.verify_bind_method_called
13
14
 
15
+ KnapsackPro.tracker.set_prerun_tests(runner.test_file_paths)
16
+
14
17
  task_name = 'knapsack_pro:minitest_run'
15
18
 
16
19
  if Rake::Task.task_defined?(task_name)
@@ -9,7 +9,9 @@ module KnapsackPro
9
9
  ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED'] = 'true'
10
10
  ENV['KNAPSACK_PRO_QUEUE_ID'] = KnapsackPro::Config::EnvGenerator.set_queue_id
11
11
 
12
- runner = new(KnapsackPro::Adapters::CucumberAdapter)
12
+ adapter_class = KnapsackPro::Adapters::CucumberAdapter
13
+ KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
14
+ runner = new(adapter_class)
13
15
 
14
16
  accumulator = {
15
17
  status: :next,
@@ -9,7 +9,9 @@ module KnapsackPro
9
9
  ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED'] = 'true'
10
10
  ENV['KNAPSACK_PRO_QUEUE_ID'] = KnapsackPro::Config::EnvGenerator.set_queue_id
11
11
 
12
- runner = new(KnapsackPro::Adapters::MinitestAdapter)
12
+ adapter_class = KnapsackPro::Adapters::MinitestAdapter
13
+ KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
14
+ runner = new(adapter_class)
13
15
 
14
16
  # Add test_dir to load path to make work:
15
17
  # require 'test_helper'
@@ -12,6 +12,7 @@ module KnapsackPro
12
12
  ENV['KNAPSACK_PRO_QUEUE_ID'] = KnapsackPro::Config::EnvGenerator.set_queue_id
13
13
 
14
14
  adapter_class = KnapsackPro::Adapters::RSpecAdapter
15
+ KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
15
16
  runner = new(adapter_class)
16
17
 
17
18
  cli_args = (args || '').split
@@ -109,9 +110,9 @@ module KnapsackPro
109
110
  def self.log_rspec_command(cli_args, test_file_paths, type)
110
111
  case type
111
112
  when :subset_queue
112
- KnapsackPro.logger.info("To retry in development the subset of tests fetched from API queue please run below command on your machine. If you use --order random then remember to add proper --seed 123 that you will find at the end of rspec command.")
113
+ KnapsackPro.logger.info("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine. (If you use the `-- order random` option, remember to add correct `--seed 123` that you can find at the end of the RSpec output.)")
113
114
  when :end_of_queue
114
- KnapsackPro.logger.info("To retry in development the tests for this CI node please run below command on your machine. It will run all tests in a single run. If you need to reproduce a particular subset of tests fetched from API queue then above after each request to Knapsack Pro API you will find example rspec command.")
115
+ KnapsackPro.logger.info("To retry all the tests assigned to this CI node, please run the following command on your machine:")
115
116
  end
116
117
 
117
118
  stringify_cli_args = cli_args.join(' ')
@@ -6,6 +6,7 @@ module KnapsackPro
6
6
  ENV['KNAPSACK_PRO_RECORDING_ENABLED'] = 'true'
7
7
 
8
8
  adapter_class = KnapsackPro::Adapters::RSpecAdapter
9
+ KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
9
10
  runner = new(adapter_class)
10
11
 
11
12
  if runner.test_files_to_execute_exist?
@@ -14,6 +15,8 @@ module KnapsackPro
14
15
  cli_args = (args || '').split
15
16
  adapter_class.ensure_no_tag_option_when_rspec_split_by_test_examples_enabled!(cli_args)
16
17
 
18
+ KnapsackPro.tracker.set_prerun_tests(runner.test_file_paths)
19
+
17
20
  require 'rspec/core/rake_task'
18
21
 
19
22
  task_name = 'knapsack_pro:rspec_run'
@@ -5,11 +5,14 @@ module KnapsackPro
5
5
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN'] = KnapsackPro::Config::Env.test_suite_token_spinach
6
6
 
7
7
  adapter_class = KnapsackPro::Adapters::SpinachAdapter
8
+ KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
8
9
  runner = new(adapter_class)
9
10
 
10
11
  if runner.test_files_to_execute_exist?
11
12
  adapter_class.verify_bind_method_called
12
13
 
14
+ KnapsackPro.tracker.set_prerun_tests(runner.test_file_paths)
15
+
13
16
  cmd = %Q[KNAPSACK_PRO_RECORDING_ENABLED=true KNAPSACK_PRO_TEST_SUITE_TOKEN=#{ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']} bundle exec spinach #{args} --features_path #{runner.test_dir} -- #{runner.stringify_test_file_paths}]
14
17
 
15
18
  Kernel.system(cmd)
@@ -6,11 +6,14 @@ module KnapsackPro
6
6
  ENV['KNAPSACK_PRO_RECORDING_ENABLED'] = 'true'
7
7
 
8
8
  adapter_class = KnapsackPro::Adapters::TestUnitAdapter
9
+ KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
9
10
  runner = new(adapter_class)
10
11
 
11
12
  if runner.test_files_to_execute_exist?
12
13
  adapter_class.verify_bind_method_called
13
14
 
15
+ KnapsackPro.tracker.set_prerun_tests(runner.test_file_paths)
16
+
14
17
  cli_args =
15
18
  (args || '').split +
16
19
  runner.test_file_paths.map do |f|
@@ -1,7 +1,6 @@
1
1
  module KnapsackPro
2
2
  class SlowTestFileDeterminer
3
3
  TIME_THRESHOLD_PER_CI_NODE = 0.7 # 70%
4
- REPORT_DIR = "#{KnapsackPro::Config::Env::TMP_DIR}/slow_test_file_determiner"
5
4
 
6
5
  # test_files: { 'path' => 'a_spec.rb', 'time_execution' => 0.0 }
7
6
  # time_execution: of build distribution (total time of CI build run)
@@ -14,12 +13,13 @@ module KnapsackPro
14
13
  end
15
14
 
16
15
  def self.save_to_json_report(test_files)
17
- FileUtils.mkdir_p(REPORT_DIR)
16
+ KnapsackPro::Config::TempFiles.ensure_temp_directory_exists!
17
+ FileUtils.mkdir_p(report_dir)
18
18
  File.write(report_path, test_files.to_json)
19
19
  end
20
20
 
21
21
  def self.read_from_json_report
22
- raise 'Report with slow test files was not generated yet. If you have enabled split by test cases https://github.com/KnapsackPro/knapsack_pro-ruby#split-test-files-by-test-cases and you see this error it means that your tests accidentally cleaned up tmp/knapsack_pro directory. Please do not remove this directory during tests runtime!' unless File.exists?(report_path)
22
+ raise 'The report with slow test files has not been generated yet. If you have enabled split by test cases https://github.com/KnapsackPro/knapsack_pro-ruby#split-test-files-by-test-cases and you see this error it means that your tests accidentally cleaned up the .knapsack_pro directory. Please do not remove this directory during tests runtime!' unless File.exist?(report_path)
23
23
  slow_test_files_json_report = File.read(report_path)
24
24
  JSON.parse(slow_test_files_json_report)
25
25
  end
@@ -27,7 +27,11 @@ module KnapsackPro
27
27
  private
28
28
 
29
29
  def self.report_path
30
- "#{REPORT_DIR}/slow_test_files_node_#{KnapsackPro::Config::Env.ci_node_index}.json"
30
+ "#{report_dir}/slow_test_files_node_#{KnapsackPro::Config::Env.ci_node_index}.json"
31
+ end
32
+
33
+ def self.report_dir
34
+ "#{KnapsackPro::Config::TempFiles::TEMP_DIRECTORY_PATH}/slow_test_file_determiner"
31
35
  end
32
36
  end
33
37
  end