Class: KnapsackPro::QueueAllocator
- Inherits:
-
Object
- Object
- KnapsackPro::QueueAllocator
- Defined in:
- lib/knapsack_pro/queue_allocator.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ QueueAllocator
constructor
A new instance of QueueAllocator.
- #test_file_paths(can_initialize_queue, executed_test_files) ⇒ Object
Constructor Details
#initialize(args) ⇒ QueueAllocator
Returns a new instance of QueueAllocator.
3 4 5 6 7 8 9 10 |
# File 'lib/knapsack_pro/queue_allocator.rb', line 3 def initialize(args) @fast_and_slow_test_files_to_run = args.fetch(:fast_and_slow_test_files_to_run) @fallback_mode_test_files = args.fetch(:fallback_mode_test_files) @ci_node_total = args.fetch(:ci_node_total) @ci_node_index = args.fetch(:ci_node_index) @ci_node_build_id = args.fetch(:ci_node_build_id) @repository_adapter = args.fetch(:repository_adapter) end |
Instance Method Details
#test_file_paths(can_initialize_queue, executed_test_files) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/knapsack_pro/queue_allocator.rb', line 12 def test_file_paths(can_initialize_queue, executed_test_files) return [] if @fallback_activated action = build_action(can_initialize_queue, attempt_connect_to_queue: can_initialize_queue) connection = KnapsackPro::Client::Connection.new(action) response = connection.call # when attempt to connect to existing queue on API side failed because queue does not exist yet if can_initialize_queue && connection.success? && connection.api_code == KnapsackPro::Client::API::V1::Queues::CODE_ATTEMPT_CONNECT_TO_QUEUE_FAILED # make attempt to initalize a new queue on API side action = build_action(can_initialize_queue, attempt_connect_to_queue: 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? = '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' KnapsackPro.logger.error() raise elsif KnapsackPro::Config::Env.ci_node_retry_count > 0 = '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://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' unless KnapsackPro::Config::Env.fixed_queue_split? += ' Please ensure you have set KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true to allow Knapsack Pro API remember the recorded CI node tests so when you retry failed tests on the CI node then the same set of tests will be executed. See more https://github.com/KnapsackPro/knapsack_pro-ruby#knapsack_pro_fixed_queue_split-remember-queue-split-on-retry-ci-node' end KnapsackPro.logger.error() raise else @fallback_activated = true KnapsackPro.logger.warn("Fallback mode started. We could not connect with Knapsack Pro API. Your tests will be executed based on directory names. If other CI nodes were able to connect with Knapsack Pro API then you may notice that some of the test files will be executed twice across CI nodes. The most important thing is to guarantee each of test files is run at least once! Read more about fallback mode at https://knapsackpro.com/faq/question/what-happens-when-knapsack-pro-api-is-not-availablenot-reachable-temporarily") fallback_test_files(executed_test_files) end end |