lib/knapsack_pro/allocator.rb in knapsack_pro-3.5.0 vs lib/knapsack_pro/allocator.rb in knapsack_pro-3.6.0
- old
+ new
@@ -7,12 +7,22 @@
@ci_node_index = args.fetch(:ci_node_index)
@repository_adapter = args.fetch(:repository_adapter)
end
def test_file_paths
- connection = KnapsackPro::Client::Connection.new(build_action)
+ action = build_action(cache_read_attempt: true)
+ connection = KnapsackPro::Client::Connection.new(action)
response = connection.call
+
+ # when a cache miss because the test suite split was not cached yet
+ if connection.success? && connection.api_code == KnapsackPro::Client::API::V1::BuildDistributions::TEST_SUITE_SPLIT_CACHE_MISS_CODE
+ # make an attempt to initalize a new test suite split on the API side
+ action = build_action(cache_read_attempt: false)
+ connection = KnapsackPro::Client::Connection.new(action)
+ response = connection.call
+ end
+
if connection.success?
raise ArgumentError.new(response) if connection.errors?
prepare_test_files(response)
elsif !KnapsackPro::Config::Env.fallback_mode_enabled?
message = '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://github.com/KnapsackPro/knapsack_pro-ruby#required-ci-configuration-if-you-use-retry-single-failed-ci-node-feature-on-your-ci-server-when-knapsack_pro_fixed_queue_splittrue-in-queue-mode-or-knapsack_pro_fixed_test_suite_splittrue-in-regular-mode'
@@ -45,16 +55,22 @@
def encrypted_branch
KnapsackPro::Crypto::BranchEncryptor.call(repository_adapter.branch)
end
- def build_action
+ def build_action(cache_read_attempt:)
+ test_files =
+ unless cache_read_attempt
+ encrypted_test_files
+ end
+
KnapsackPro::Client::API::V1::BuildDistributions.subset(
+ cache_read_attempt: cache_read_attempt,
commit_hash: repository_adapter.commit_hash,
branch: encrypted_branch,
node_total: ci_node_total,
node_index: ci_node_index,
- test_files: encrypted_test_files,
+ test_files: test_files,
)
end
def prepare_test_files(response)
decrypted_test_files = KnapsackPro::Crypto::Decryptor.call(fast_and_slow_test_files_to_run, response['test_files'])