knapsack_pro 9.0.0 → 9.1.0

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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/knapsack_pro/adapters/minitest_adapter.rb +8 -13
  3. data/lib/knapsack_pro/client/connection.rb +1 -1
  4. data/lib/knapsack_pro/config/env.rb +1 -24
  5. data/lib/knapsack_pro/version.rb +1 -1
  6. metadata +2 -196
  7. data/.circleci/config.yml +0 -468
  8. data/.github/assets/install-button.png +0 -0
  9. data/.github/assets/knapsack-diamonds.png +0 -0
  10. data/.github/dependabot.yml +0 -11
  11. data/.github/pull_request_template.md +0 -11
  12. data/.gitignore +0 -39
  13. data/.rspec +0 -5
  14. data/CHANGELOG.md +0 -1995
  15. data/Gemfile +0 -13
  16. data/LICENSE +0 -22
  17. data/README.md +0 -90
  18. data/Rakefile +0 -2
  19. data/knapsack_pro.gemspec +0 -43
  20. data/spec/fixtures/test_file_list_source_file.txt +0 -6
  21. data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/invalid_test_suite_token.yml +0 -59
  22. data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/success.yml +0 -61
  23. data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/invalid_test_suite_token.yml +0 -50
  24. data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/success.yml +0 -50
  25. data/spec/integration/api/build_distributions_subset_spec.rb +0 -77
  26. data/spec/integration/api/build_subsets_create_spec.rb +0 -77
  27. data/spec/integration/runners/fallback_spec.rb +0 -131
  28. data/spec/integration/runners/queue/cucumber_runner_fallback_spec.rb +0 -129
  29. data/spec/integration/runners/queue/minitest_runner_fallback_spec.rb +0 -129
  30. data/spec/integration/runners/queue/rspec_runner.rb +0 -80
  31. data/spec/integration/runners/queue/rspec_runner_fallback_spec.rb +0 -137
  32. data/spec/integration/runners/queue/rspec_runner_spec.rb +0 -2672
  33. data/spec/knapsack_pro/adapters/base_adapter_spec.rb +0 -221
  34. data/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb +0 -216
  35. data/spec/knapsack_pro/adapters/minitest_adapter_spec.rb +0 -189
  36. data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +0 -427
  37. data/spec/knapsack_pro/adapters/spinach_adapter_spec.rb +0 -61
  38. data/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb +0 -86
  39. data/spec/knapsack_pro/base_allocator_builder_spec.rb +0 -102
  40. data/spec/knapsack_pro/build_distribution_fetcher_spec.rb +0 -89
  41. data/spec/knapsack_pro/client/api/action_spec.rb +0 -17
  42. data/spec/knapsack_pro/client/api/v1/base_spec.rb +0 -2
  43. data/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb +0 -95
  44. data/spec/knapsack_pro/client/api/v1/build_subsets_spec.rb +0 -35
  45. data/spec/knapsack_pro/client/api/v1/queues_spec.rb +0 -83
  46. data/spec/knapsack_pro/client/connection_spec.rb +0 -581
  47. data/spec/knapsack_pro/config/ci/app_veyor_spec.rb +0 -87
  48. data/spec/knapsack_pro/config/ci/base_spec.rb +0 -10
  49. data/spec/knapsack_pro/config/ci/buildkite_spec.rb +0 -135
  50. data/spec/knapsack_pro/config/ci/circle_spec.rb +0 -122
  51. data/spec/knapsack_pro/config/ci/cirrus_ci_spec.rb +0 -87
  52. data/spec/knapsack_pro/config/ci/codefresh_spec.rb +0 -81
  53. data/spec/knapsack_pro/config/ci/codeship_spec.rb +0 -80
  54. data/spec/knapsack_pro/config/ci/github_actions_spec.rb +0 -140
  55. data/spec/knapsack_pro/config/ci/gitlab_ci_spec.rb +0 -137
  56. data/spec/knapsack_pro/config/ci/heroku_spec.rb +0 -87
  57. data/spec/knapsack_pro/config/ci/semaphore2_spec.rb +0 -133
  58. data/spec/knapsack_pro/config/ci/semaphore_spec.rb +0 -87
  59. data/spec/knapsack_pro/config/ci/travis_spec.rb +0 -73
  60. data/spec/knapsack_pro/config/env_generator_spec.rb +0 -52
  61. data/spec/knapsack_pro/config/env_spec.rb +0 -1291
  62. data/spec/knapsack_pro/config/temp_files_spec.rb +0 -25
  63. data/spec/knapsack_pro/crypto/branch_encryptor_spec.rb +0 -53
  64. data/spec/knapsack_pro/crypto/decryptor_spec.rb +0 -83
  65. data/spec/knapsack_pro/crypto/digestor_spec.rb +0 -13
  66. data/spec/knapsack_pro/crypto/encryptor_spec.rb +0 -58
  67. data/spec/knapsack_pro/formatters/time_tracker_fetcher_spec.rb +0 -27
  68. data/spec/knapsack_pro/formatters/time_tracker_spec.rb +0 -448
  69. data/spec/knapsack_pro/hooks/queue_spec.rb +0 -199
  70. data/spec/knapsack_pro/presenter_spec.rb +0 -57
  71. data/spec/knapsack_pro/pure/queue/rspec_pure_spec.rb +0 -248
  72. data/spec/knapsack_pro/queue_spec.rb +0 -35
  73. data/spec/knapsack_pro/report_spec.rb +0 -232
  74. data/spec/knapsack_pro/repository_adapter_initiator_spec.rb +0 -21
  75. data/spec/knapsack_pro/repository_adapters/base_adapter_spec.rb +0 -13
  76. data/spec/knapsack_pro/repository_adapters/env_adapter_spec.rb +0 -27
  77. data/spec/knapsack_pro/repository_adapters/git_adapter_spec.rb +0 -106
  78. data/spec/knapsack_pro/runners/base_runner_spec.rb +0 -87
  79. data/spec/knapsack_pro/runners/cucumber_runner_spec.rb +0 -92
  80. data/spec/knapsack_pro/runners/minitest_runner_spec.rb +0 -57
  81. data/spec/knapsack_pro/runners/queue/base_runner_spec.rb +0 -73
  82. data/spec/knapsack_pro/runners/queue/cucumber_runner_spec.rb +0 -209
  83. data/spec/knapsack_pro/runners/queue/minitest_runner_spec.rb +0 -203
  84. data/spec/knapsack_pro/runners/rspec_runner_spec.rb +0 -111
  85. data/spec/knapsack_pro/runners/spinach_runner_spec.rb +0 -56
  86. data/spec/knapsack_pro/runners/test_unit_runner_spec.rb +0 -62
  87. data/spec/knapsack_pro/slow_test_file_determiner_spec.rb +0 -119
  88. data/spec/knapsack_pro/slow_test_file_finder_spec.rb +0 -42
  89. data/spec/knapsack_pro/task_loader_spec.rb +0 -14
  90. data/spec/knapsack_pro/test_case_detectors/rspec_test_example_detector_spec.rb +0 -217
  91. data/spec/knapsack_pro/test_case_mergers/base_merger_spec.rb +0 -27
  92. data/spec/knapsack_pro/test_case_mergers/rspec_merger_spec.rb +0 -81
  93. data/spec/knapsack_pro/test_file_cleaner_spec.rb +0 -11
  94. data/spec/knapsack_pro/test_file_finder_spec.rb +0 -176
  95. data/spec/knapsack_pro/test_file_pattern_spec.rb +0 -49
  96. data/spec/knapsack_pro/test_file_presenter_spec.rb +0 -22
  97. data/spec/knapsack_pro/test_files_with_test_cases_composer_spec.rb +0 -41
  98. data/spec/knapsack_pro/test_flat_distributor_spec.rb +0 -60
  99. data/spec/knapsack_pro/tracker_spec.rb +0 -184
  100. data/spec/knapsack_pro/utils_spec.rb +0 -55
  101. data/spec/knapsack_pro_spec.rb +0 -116
  102. data/spec/spec_helper.rb +0 -47
  103. data/spec/support/.gitkeep +0 -0
  104. data/spec/support/fakes/cucumber.rb +0 -25
  105. data/spec/support/fakes/minitest.rb +0 -18
  106. data/spec/support/shared_examples/adapter.rb +0 -17
  107. data/spec_fake/controllers/users_controller_spec.rb +0 -0
  108. data/spec_fake/models/admin_spec.rb +0 -0
  109. data/spec_fake/models/user_spec.rb +0 -0
  110. data/spec_fake/spec_helper.rb +0 -0
  111. data/spec_time_tracker/spec_helper.rb +0 -29
  112. data/test_fake/a_test.rb +0 -0
  113. data/test_fake/b_test.rb +0 -0
@@ -1,131 +0,0 @@
1
- require 'open3'
2
- require 'ostruct'
3
- require 'tempfile'
4
-
5
- ['RSpec', 'Minitest', 'Cucumber'].each do |runner|
6
- describe "#{Object.const_get("KnapsackPro::Runners::#{runner}Runner")} Fallback - Integration tests" do
7
- def log(stdout, stderr, status)
8
- puts '='*50
9
- puts 'STDOUT:'
10
- puts stdout
11
- puts
12
-
13
- puts '='*50
14
- puts 'STDERR:'
15
- puts stderr
16
- puts
17
-
18
- puts '='*50
19
- puts 'Exit status code:'
20
- puts status
21
- puts
22
- end
23
-
24
- subject do
25
- stdout, stderr, status = Open3.capture3("ruby #{@task.path}")
26
- log(stdout, stderr, status) if ENV['TEST__SHOW_DEBUG_LOG'] == 'true'
27
- OpenStruct.new(stdout: stdout, stderr: stderr, exit_code: status.exitstatus)
28
- end
29
-
30
- before(:each) do
31
- ENV['KNAPSACK_PRO_ENDPOINT'] = 'https://fail.knapsackpro.com' # ensure the API is not reachable
32
- ENV['KNAPSACK_PRO_MAX_REQUEST_RETRIES'] = '1' # only try once to reach the API
33
- end
34
-
35
- around(:each) do |example|
36
- Tempfile.create do |file|
37
- file.write(<<~CONTENT)
38
- require 'knapsack_pro'
39
-
40
- ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_#{runner.upcase}'] = SecureRandom.hex
41
- ENV['KNAPSACK_PRO_CI_NODE_BUILD_ID'] = SecureRandom.uuid
42
-
43
- #{Object.const_get("KnapsackPro::Runners::#{runner}Runner")}.run('')
44
- CONTENT
45
- file.rewind
46
-
47
- @task = file
48
- example.run
49
- end
50
- end
51
-
52
- after(:each) do
53
- ENV.delete('KNAPSACK_PRO_ENDPOINT')
54
- ENV.delete('KNAPSACK_PRO_MAX_REQUEST_RETRIES')
55
- end
56
-
57
- context 'with fallback mode disabled' do
58
- before(:each) do
59
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ENABLED'] = 'false'
60
- end
61
-
62
- after(:each) do
63
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ENABLED')
64
- end
65
-
66
- it 'exits with 1 and logs the error' do
67
- actual = subject
68
-
69
- expect(actual.exit_code).to eq 1
70
-
71
- expect(actual.stdout).to include('ERROR -- knapsack_pro: Fallback Mode was disabled with KNAPSACK_PRO_FALLBACK_MODE_ENABLED=false. Please restart this CI node to retry tests. Most likely Fallback Mode was disabled due to https://knapsackpro.com/perma/ruby/regular-mode-connection-error-with-fallback-enabled-false')
72
- end
73
-
74
- context 'with a user defined exit code' do
75
- before do
76
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE'] = '123'
77
- end
78
-
79
- after do
80
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE')
81
- end
82
-
83
- it 'exits with the passed exit code and logs the error' do
84
- actual = subject
85
-
86
- expect(actual.exit_code).to eq 123
87
-
88
- expect(actual.stdout).to include('ERROR -- knapsack_pro: Fallback Mode was disabled with KNAPSACK_PRO_FALLBACK_MODE_ENABLED=false. Please restart this CI node to retry tests. Most likely Fallback Mode was disabled due to https://knapsackpro.com/perma/ruby/regular-mode-connection-error-with-fallback-enabled-false')
89
- end
90
- end
91
- end
92
-
93
- context 'with fallback mode enabled and positive node retry count' do
94
- before(:each) do
95
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ENABLED'] = 'true'
96
- ENV['KNAPSACK_PRO_CI_NODE_RETRY_COUNT'] = '1'
97
- end
98
-
99
- after(:each) do
100
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ENABLED')
101
- ENV.delete('KNAPSACK_PRO_CI_NODE_RETRY_COUNT')
102
- end
103
-
104
- it 'exits with 1 and logs the error' do
105
- actual = subject
106
-
107
- expect(actual.exit_code).to eq 1
108
-
109
- expect(actual.stdout).to include('ERROR -- knapsack_pro: knapsack_pro gem could not connect to Knapsack Pro API and the Fallback Mode cannot be used this time. Running tests in Fallback Mode are not allowed for retried parallel CI node to avoid running the wrong set of tests. Please manually retry this parallel job on your CI server then knapsack_pro gem will try to connect to Knapsack Pro API again and will run a correct set of tests for this CI node. Learn more https://knapsackpro.com/perma/ruby/regular-mode-connection-error-with-fallback-enabled-true-and-positive-retry-count')
110
- end
111
-
112
- context 'with a user defined exit code' do
113
- before do
114
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE'] = '123'
115
- end
116
-
117
- after do
118
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE')
119
- end
120
-
121
- it 'exits with the passed exit code and logs the error' do
122
- actual = subject
123
-
124
- expect(actual.exit_code).to eq 123
125
-
126
- expect(actual.stdout).to include('ERROR -- knapsack_pro: knapsack_pro gem could not connect to Knapsack Pro API and the Fallback Mode cannot be used this time. Running tests in Fallback Mode are not allowed for retried parallel CI node to avoid running the wrong set of tests. Please manually retry this parallel job on your CI server then knapsack_pro gem will try to connect to Knapsack Pro API again and will run a correct set of tests for this CI node. Learn more https://knapsackpro.com/perma/ruby/regular-mode-connection-error-with-fallback-enabled-true-and-positive-retry-count')
127
- end
128
- end
129
- end
130
- end
131
- end
@@ -1,129 +0,0 @@
1
- require 'open3'
2
- require 'ostruct'
3
- require 'tempfile'
4
-
5
- describe "#{KnapsackPro::Runners::Queue::CucumberRunner} Fallback - Integration tests" do
6
- def log(stdout, stderr, status)
7
- puts '='*50
8
- puts 'STDOUT:'
9
- puts stdout
10
- puts
11
-
12
- puts '='*50
13
- puts 'STDERR:'
14
- puts stderr
15
- puts
16
-
17
- puts '='*50
18
- puts 'Exit status code:'
19
- puts status
20
- puts
21
- end
22
-
23
- subject do
24
- stdout, stderr, status = Open3.capture3("ruby #{@task.path}")
25
- log(stdout, stderr, status) if ENV['TEST__SHOW_DEBUG_LOG'] == 'true'
26
- OpenStruct.new(stdout: stdout, stderr: stderr, exit_code: status.exitstatus)
27
- end
28
-
29
- before(:each) do
30
- ENV['KNAPSACK_PRO_ENDPOINT'] = 'https://fail.knapsackpro.com' # ensure the API is not reachable
31
- ENV['KNAPSACK_PRO_MAX_REQUEST_RETRIES'] = '1' # only try once to reach the API
32
- end
33
-
34
- around(:each) do |example|
35
- Tempfile.create do |file|
36
- file.write(<<~CONTENT)
37
- require 'knapsack_pro'
38
-
39
- ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER'] = SecureRandom.hex
40
- ENV['KNAPSACK_PRO_CI_NODE_BUILD_ID'] = SecureRandom.uuid
41
-
42
- #{KnapsackPro::Runners::Queue::CucumberRunner}.run('')
43
- CONTENT
44
- file.rewind
45
-
46
- @task = file
47
- example.run
48
- end
49
- end
50
-
51
- after(:each) do
52
- ENV.delete('KNAPSACK_PRO_ENDPOINT')
53
- ENV.delete('KNAPSACK_PRO_MAX_REQUEST_RETRIES')
54
- end
55
-
56
- context 'with fallback mode disabled' do
57
- before(:each) do
58
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ENABLED'] = 'false'
59
- end
60
-
61
- after(:each) do
62
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ENABLED')
63
- end
64
-
65
- it 'exits with 1 and logs the error' do
66
- actual = subject
67
-
68
- expect(actual.exit_code).to eq 1
69
-
70
- expect(actual.stdout).to include('ERROR -- knapsack_pro: Fallback Mode was disabled with KNAPSACK_PRO_FALLBACK_MODE_ENABLED=false. Please restart this CI node to retry tests. Most likely Fallback Mode was disabled due to https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-false')
71
- end
72
-
73
- context 'with a user defined exit code' do
74
- before do
75
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE'] = '123'
76
- end
77
-
78
- after do
79
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE')
80
- end
81
-
82
- it 'exits with the passed exit code and logs the error' do
83
- actual = subject
84
-
85
- expect(actual.exit_code).to eq 123
86
-
87
- expect(actual.stdout).to include('ERROR -- knapsack_pro: Fallback Mode was disabled with KNAPSACK_PRO_FALLBACK_MODE_ENABLED=false. Please restart this CI node to retry tests. Most likely Fallback Mode was disabled due to https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-false')
88
- end
89
- end
90
- end
91
-
92
- context 'with fallback mode enabled and positive node retry count' do
93
- before(:each) do
94
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ENABLED'] = 'true'
95
- ENV['KNAPSACK_PRO_CI_NODE_RETRY_COUNT'] = '1'
96
- end
97
-
98
- after(:each) do
99
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ENABLED')
100
- ENV.delete('KNAPSACK_PRO_CI_NODE_RETRY_COUNT')
101
- end
102
-
103
- it 'exits with 1 and logs the error' do
104
- actual = subject
105
-
106
- expect(actual.exit_code).to eq 1
107
-
108
- expect(actual.stdout).to include('ERROR -- knapsack_pro: knapsack_pro gem could not connect to Knapsack Pro API and the Fallback Mode cannot be used this time. Running tests in Fallback Mode are not allowed for retried parallel CI node to avoid running the wrong set of tests. Please manually retry this parallel job on your CI server then knapsack_pro gem will try to connect to Knapsack Pro API again and will run a correct set of tests for this CI node. Learn more https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-true-and-positive-retry-count')
109
- end
110
-
111
- context 'with a user defined exit code' do
112
- before do
113
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE'] = '123'
114
- end
115
-
116
- after do
117
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE')
118
- end
119
-
120
- it 'exits with the passed exit code and logs the error' do
121
- actual = subject
122
-
123
- expect(actual.exit_code).to eq 123
124
-
125
- expect(actual.stdout).to include('ERROR -- knapsack_pro: knapsack_pro gem could not connect to Knapsack Pro API and the Fallback Mode cannot be used this time. Running tests in Fallback Mode are not allowed for retried parallel CI node to avoid running the wrong set of tests. Please manually retry this parallel job on your CI server then knapsack_pro gem will try to connect to Knapsack Pro API again and will run a correct set of tests for this CI node. Learn more https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-true-and-positive-retry-count')
126
- end
127
- end
128
- end
129
- end
@@ -1,129 +0,0 @@
1
- require 'open3'
2
- require 'ostruct'
3
- require 'tempfile'
4
-
5
- describe "#{KnapsackPro::Runners::Queue::MinitestRunner} Fallback - Integration tests" do
6
- def log(stdout, stderr, status)
7
- puts '='*50
8
- puts 'STDOUT:'
9
- puts stdout
10
- puts
11
-
12
- puts '='*50
13
- puts 'STDERR:'
14
- puts stderr
15
- puts
16
-
17
- puts '='*50
18
- puts 'Exit status code:'
19
- puts status
20
- puts
21
- end
22
-
23
- subject do
24
- stdout, stderr, status = Open3.capture3("ruby #{@task.path}")
25
- log(stdout, stderr, status) if ENV['TEST__SHOW_DEBUG_LOG'] == 'true'
26
- OpenStruct.new(stdout: stdout, stderr: stderr, exit_code: status.exitstatus)
27
- end
28
-
29
- before(:each) do
30
- ENV['KNAPSACK_PRO_ENDPOINT'] = 'https://fail.knapsackpro.com' # ensure the API is not reachable
31
- ENV['KNAPSACK_PRO_MAX_REQUEST_RETRIES'] = '1' # only try once to reach the API
32
- end
33
-
34
- around(:each) do |example|
35
- Tempfile.create do |file|
36
- file.write(<<~CONTENT)
37
- require 'knapsack_pro'
38
-
39
- ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST'] = SecureRandom.hex
40
- ENV['KNAPSACK_PRO_CI_NODE_BUILD_ID'] = SecureRandom.uuid
41
-
42
- #{KnapsackPro::Runners::Queue::MinitestRunner}.run('')
43
- CONTENT
44
- file.rewind
45
-
46
- @task = file
47
- example.run
48
- end
49
- end
50
-
51
- after(:each) do
52
- ENV.delete('KNAPSACK_PRO_ENDPOINT')
53
- ENV.delete('KNAPSACK_PRO_MAX_REQUEST_RETRIES')
54
- end
55
-
56
- context 'with fallback mode disabled' do
57
- before(:each) do
58
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ENABLED'] = 'false'
59
- end
60
-
61
- after(:each) do
62
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ENABLED')
63
- end
64
-
65
- it 'exits with 1 and logs the error' do
66
- actual = subject
67
-
68
- expect(actual.exit_code).to eq 1
69
-
70
- expect(actual.stdout).to include('ERROR -- knapsack_pro: Fallback Mode was disabled with KNAPSACK_PRO_FALLBACK_MODE_ENABLED=false. Please restart this CI node to retry tests. Most likely Fallback Mode was disabled due to https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-false')
71
- end
72
-
73
- context 'with a user defined exit code' do
74
- before do
75
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE'] = '123'
76
- end
77
-
78
- after do
79
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE')
80
- end
81
-
82
- it 'exits with the passed exit code and logs the error' do
83
- actual = subject
84
-
85
- expect(actual.exit_code).to eq 123
86
-
87
- expect(actual.stdout).to include('ERROR -- knapsack_pro: Fallback Mode was disabled with KNAPSACK_PRO_FALLBACK_MODE_ENABLED=false. Please restart this CI node to retry tests. Most likely Fallback Mode was disabled due to https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-false')
88
- end
89
- end
90
- end
91
-
92
- context 'with fallback mode enabled and positive node retry count' do
93
- before(:each) do
94
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ENABLED'] = 'true'
95
- ENV['KNAPSACK_PRO_CI_NODE_RETRY_COUNT'] = '1'
96
- end
97
-
98
- after(:each) do
99
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ENABLED')
100
- ENV.delete('KNAPSACK_PRO_CI_NODE_RETRY_COUNT')
101
- end
102
-
103
- it 'exits with 1 and logs the error' do
104
- actual = subject
105
-
106
- expect(actual.exit_code).to eq 1
107
-
108
- expect(actual.stdout).to include('ERROR -- knapsack_pro: knapsack_pro gem could not connect to Knapsack Pro API and the Fallback Mode cannot be used this time. Running tests in Fallback Mode are not allowed for retried parallel CI node to avoid running the wrong set of tests. Please manually retry this parallel job on your CI server then knapsack_pro gem will try to connect to Knapsack Pro API again and will run a correct set of tests for this CI node. Learn more https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-true-and-positive-retry-count')
109
- end
110
-
111
- context 'with a user defined exit code' do
112
- before do
113
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE'] = '123'
114
- end
115
-
116
- after do
117
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE')
118
- end
119
-
120
- it 'exits with the passed exit code and logs the error' do
121
- actual = subject
122
-
123
- expect(actual.exit_code).to eq 123
124
-
125
- expect(actual.stdout).to include('ERROR -- knapsack_pro: knapsack_pro gem could not connect to Knapsack Pro API and the Fallback Mode cannot be used this time. Running tests in Fallback Mode are not allowed for retried parallel CI node to avoid running the wrong set of tests. Please manually retry this parallel job on your CI server then knapsack_pro gem will try to connect to Knapsack Pro API again and will run a correct set of tests for this CI node. Learn more https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-true-and-positive-retry-count')
126
- end
127
- end
128
- end
129
- end
@@ -1,80 +0,0 @@
1
- require 'knapsack_pro'
2
- require 'json'
3
-
4
- ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC'] = SecureRandom.hex
5
- ENV['KNAPSACK_PRO_CI_NODE_BUILD_ID'] = SecureRandom.uuid
6
- ENV['KNAPSACK_PRO_TEST_DIR'] = 'spec_integration'
7
- ENV['KNAPSACK_PRO_TEST_FILE_PATTERN'] = "spec_integration/**{,/*/**}/*_spec.rb"
8
-
9
- RSPEC_OPTIONS = ENV.fetch('TEST__RSPEC_OPTIONS')
10
- SHOW_DEBUG_LOG = ENV['TEST__SHOW_DEBUG_LOG'] == 'true'
11
- SPEC_BATCHES = JSON.load(ENV.fetch('TEST__SPEC_BATCHES'))
12
-
13
- class IntegrationTestLogger
14
- def self.log(message)
15
- puts "[INTEGRATION TEST] #{message}"
16
- end
17
- end
18
-
19
- module KnapsackProExtensions
20
- module QueueAllocatorExtension
21
- def test_file_paths(can_initialize_queue, executed_test_files)
22
- @batch_index ||= 0
23
- last_batch = []
24
- batches = [*SPEC_BATCHES, last_batch]
25
- tests = batches[@batch_index]
26
- @batch_index += 1
27
-
28
- if SHOW_DEBUG_LOG
29
- IntegrationTestLogger.log("Stubbed tests from the Queue API: #{tests.inspect}")
30
- end
31
-
32
- tests
33
- end
34
- end
35
-
36
- module Report
37
- def create_build_subset(test_files)
38
- if ENV['TEST__LOG_EXECUTION_TIMES']
39
- have_execution_time = test_files.all? { _1.fetch('time_execution') > 0 }
40
- IntegrationTestLogger.log("test_files: #{test_files.size}, test files have execution time: #{have_execution_time}")
41
- end
42
-
43
- return unless SHOW_DEBUG_LOG
44
- IntegrationTestLogger.log("Stubbed the #{__method__} method")
45
- end
46
- end
47
-
48
- module RSpecAdapter
49
- def test_file_cases_for(slow_test_files)
50
- IntegrationTestLogger.log("Stubbed test file cases for slow test files: #{slow_test_files}")
51
-
52
- test_file_paths = JSON.load(ENV.fetch('TEST__TEST_FILE_CASES_FOR_SLOW_TEST_FILES'))
53
- test_file_paths.map do |path|
54
- { 'path' => path }
55
- end
56
- end
57
- end
58
- end
59
-
60
- KnapsackPro::QueueAllocator.prepend(KnapsackProExtensions::QueueAllocatorExtension)
61
-
62
- module KnapsackPro
63
- class Report
64
- class << self
65
- prepend KnapsackProExtensions::Report
66
- end
67
- end
68
- end
69
-
70
- module KnapsackPro
71
- module Adapters
72
- class RSpecAdapter
73
- class << self
74
- prepend KnapsackProExtensions::RSpecAdapter
75
- end
76
- end
77
- end
78
- end
79
-
80
- KnapsackPro::Runners::Queue::RSpecRunner.run(RSPEC_OPTIONS)
@@ -1,137 +0,0 @@
1
- require 'open3'
2
- require 'ostruct'
3
- require 'tempfile'
4
-
5
- describe "#{KnapsackPro::Runners::Queue::RSpecRunner} Fallback - Integration tests" do
6
- def log(stdout, stderr, status)
7
- puts '='*50
8
- puts 'STDOUT:'
9
- puts stdout
10
- puts
11
-
12
- puts '='*50
13
- puts 'STDERR:'
14
- puts stderr
15
- puts
16
-
17
- puts '='*50
18
- puts 'Exit status code:'
19
- puts status
20
- puts
21
- end
22
-
23
- subject do
24
- stdout, stderr, status = Open3.capture3("ruby #{@task.path}")
25
- log(stdout, stderr, status) if ENV['TEST__SHOW_DEBUG_LOG'] == 'true'
26
- OpenStruct.new(stdout: stdout, stderr: stderr, exit_code: status.exitstatus)
27
- end
28
-
29
- before(:each) do
30
- ENV['KNAPSACK_PRO_ENDPOINT'] = 'https://fail.knapsackpro.com' # ensure the API is not reachable
31
- ENV['KNAPSACK_PRO_MAX_REQUEST_RETRIES'] = '1' # only try once to reach the API
32
- end
33
-
34
- around(:each) do |example|
35
- Tempfile.create do |file|
36
- file.write(<<~CONTENT)
37
- require 'knapsack_pro'
38
-
39
- ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC'] = SecureRandom.hex
40
- ENV['KNAPSACK_PRO_CI_NODE_BUILD_ID'] = SecureRandom.uuid
41
-
42
- #{KnapsackPro::Runners::Queue::RSpecRunner}.run('')
43
- CONTENT
44
- file.rewind
45
-
46
- @task = file
47
- example.run
48
- end
49
- end
50
-
51
- after(:each) do
52
- ENV.delete('KNAPSACK_PRO_ENDPOINT')
53
- ENV.delete('KNAPSACK_PRO_MAX_REQUEST_RETRIES')
54
- end
55
-
56
- context 'with fallback mode disabled' do
57
- before(:each) do
58
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ENABLED'] = 'false'
59
- end
60
-
61
- after(:each) do
62
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ENABLED')
63
- end
64
-
65
- it 'exits with 1 and logs error and summary' do
66
- actual = subject
67
-
68
- expect(actual.exit_code).to eq 1
69
-
70
- expect(actual.stdout).to include('ERROR -- knapsack_pro: Fallback Mode was disabled with KNAPSACK_PRO_FALLBACK_MODE_ENABLED=false. Please restart this CI node to retry tests. Most likely Fallback Mode was disabled due to https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-false')
71
- expect(actual.stdout).to include(/Finished in .* seconds \(files took .* seconds to load\)/)
72
- expect(actual.stdout).to include('0 examples, 0 failures')
73
- end
74
-
75
- context 'with a user defined exit code' do
76
- before do
77
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE'] = '123'
78
- end
79
-
80
- after do
81
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE')
82
- end
83
-
84
- it 'exits with the passed exit code and logs error and summary' do
85
- actual = subject
86
-
87
- expect(actual.exit_code).to eq 123
88
-
89
- expect(actual.stdout).to include('ERROR -- knapsack_pro: Fallback Mode was disabled with KNAPSACK_PRO_FALLBACK_MODE_ENABLED=false. Please restart this CI node to retry tests. Most likely Fallback Mode was disabled due to https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-false')
90
- expect(actual.stdout).to include(/Finished in .* seconds \(files took .* seconds to load\)/)
91
- expect(actual.stdout).to include('0 examples, 0 failures')
92
- end
93
- end
94
- end
95
-
96
- context 'with fallback mode enabled and positive node retry count' do
97
- before(:each) do
98
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ENABLED'] = 'true'
99
- ENV['KNAPSACK_PRO_CI_NODE_RETRY_COUNT'] = '1'
100
- end
101
-
102
- after(:each) do
103
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ENABLED')
104
- ENV.delete('KNAPSACK_PRO_CI_NODE_RETRY_COUNT')
105
- end
106
-
107
- it 'exits with 1 and logs error and summary' do
108
- actual = subject
109
-
110
- expect(actual.exit_code).to eq 1
111
-
112
- expect(actual.stdout).to include('ERROR -- knapsack_pro: knapsack_pro gem could not connect to Knapsack Pro API and the Fallback Mode cannot be used this time. Running tests in Fallback Mode are not allowed for retried parallel CI node to avoid running the wrong set of tests. Please manually retry this parallel job on your CI server then knapsack_pro gem will try to connect to Knapsack Pro API again and will run a correct set of tests for this CI node. Learn more https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-true-and-positive-retry-count')
113
- expect(actual.stdout).to include(/Finished in .* seconds \(files took .* seconds to load\)/)
114
- expect(actual.stdout).to include('0 examples, 0 failures')
115
- end
116
-
117
- context 'with a user defined exit code' do
118
- before do
119
- ENV['KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE'] = '123'
120
- end
121
-
122
- after do
123
- ENV.delete('KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE')
124
- end
125
-
126
- it 'exits with the passed exit code and logs error and summary' do
127
- actual = subject
128
-
129
- expect(actual.exit_code).to eq 123
130
-
131
- expect(actual.stdout).to include('ERROR -- knapsack_pro: knapsack_pro gem could not connect to Knapsack Pro API and the Fallback Mode cannot be used this time. Running tests in Fallback Mode are not allowed for retried parallel CI node to avoid running the wrong set of tests. Please manually retry this parallel job on your CI server then knapsack_pro gem will try to connect to Knapsack Pro API again and will run a correct set of tests for this CI node. Learn more https://knapsackpro.com/perma/ruby/queue-mode-connection-error-with-fallback-enabled-true-and-positive-retry-count')
132
- expect(actual.stdout).to include(/Finished in .* seconds \(files took .* seconds to load\)/)
133
- expect(actual.stdout).to include('0 examples, 0 failures')
134
- end
135
- end
136
- end
137
- end