From 3b564b1df9e292814a648d3aeabaafbcca4272a9 Mon Sep 17 00:00:00 2001 From: Jhonas Date: Wed, 29 Jan 2025 15:29:48 -0300 Subject: [PATCH] fix: add more information on the network generation application result Now that we can capture errors, we have to add more information on the result of the application of the generated network to the plan. This is done by changing the return of #syskit_apply_resolution_results to a struct that has information of the errors and the planned instances. --- lib/syskit/network_generation/async.rb | 3 --- .../network_generation/resolution_error_handler.rb | 8 ++++++++ .../network_generation/system_network_generator.rb | 2 +- lib/syskit/runtime/apply_requirement_modifications.rb | 11 ++++++++--- .../test/instance_requirement_planning_handler.rb | 8 ++++---- testfile | 0 6 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 testfile diff --git a/lib/syskit/network_generation/async.rb b/lib/syskit/network_generation/async.rb index 67404a980..a78d98594 100644 --- a/lib/syskit/network_generation/async.rb +++ b/lib/syskit/network_generation/async.rb @@ -119,9 +119,6 @@ def cancelled? class InvalidState < RuntimeError; end - SystemNetworkPlanApplyResult = - Struct.new :fulfilled, :instances, :errors, keyword_init: true - # Apply the result of the generation # # @return [Boolean] true if the result has been applied, and false diff --git a/lib/syskit/network_generation/resolution_error_handler.rb b/lib/syskit/network_generation/resolution_error_handler.rb index 1145aa55c..040157cf5 100644 --- a/lib/syskit/network_generation/resolution_error_handler.rb +++ b/lib/syskit/network_generation/resolution_error_handler.rb @@ -11,6 +11,14 @@ def initialize(errors) end end + # Reports the result of the network generation application. + SystemNetworkPlanApplyResult = + Struct.new :fulfilled, :instances, :errors, keyword_init: true do + def fulfilled? + fulfilled + end + end + # This is used to capture failures during the network generation process. Each # failure bundles the toplevel tasks that are related to the task that originates # the failure. It should be transformed into a ResolutionError for each related diff --git a/lib/syskit/network_generation/system_network_generator.rb b/lib/syskit/network_generation/system_network_generator.rb index 39552a50a..59541f749 100644 --- a/lib/syskit/network_generation/system_network_generator.rb +++ b/lib/syskit/network_generation/system_network_generator.rb @@ -497,7 +497,7 @@ def self.verify_all_deployments_are_unique( # # It performs the tests that are only needed on an abstract network, # i.e. on a network in which some tasks are still abstract - def validate_abstract_network + def validate_abstract_network(error_handler: @error_handler) self.class.verify_no_multiplexing_connections(plan) super if defined? super end diff --git a/lib/syskit/runtime/apply_requirement_modifications.rb b/lib/syskit/runtime/apply_requirement_modifications.rb index 102d9eeea..1390e0c1e 100644 --- a/lib/syskit/runtime/apply_requirement_modifications.rb +++ b/lib/syskit/runtime/apply_requirement_modifications.rb @@ -103,7 +103,10 @@ def syskit_apply_async_resolution_results begin resolution_apply_result = syskit_current_resolution.apply - return unless resolution_apply_result.fulfilled + + unless resolution_apply_result.fulfilled? + return resolution_apply_result + end ensure syskit_current_resolution_keepalive.discard_transaction @syskit_current_resolution = nil @@ -115,12 +118,14 @@ def syskit_apply_async_resolution_results resolution_apply_result.errors.group_by(&:planning_task).each do |task, e| task.failed_event.emit e.flat_map(&:original_exception) end - nil + resolution_apply_result rescue ::Exception => e # rubocop:disable Lint/RescueException running_requirement_tasks.each do |t| t.failed_event.emit(e) end - e + NetworkGeneration::SystemNetworkPlanApplyResult.new( + fulfilled: false, errors: [e] + ) end end diff --git a/lib/syskit/test/instance_requirement_planning_handler.rb b/lib/syskit/test/instance_requirement_planning_handler.rb index ff3f9b93f..3cbba2517 100644 --- a/lib/syskit/test/instance_requirement_planning_handler.rb +++ b/lib/syskit/test/instance_requirement_planning_handler.rb @@ -56,17 +56,17 @@ def apply_requirements ) end - def finished? + def finished? # rubocop:disable Metrics/AbcSize Thread.pass if @plan.syskit_has_async_resolution? return unless @plan.syskit_finished_async_resolution? - error = @plan.syskit_apply_async_resolution_results - return true if error + resolution_results = @plan.syskit_apply_async_resolution_results + return true unless resolution_results.fulfilled? return unless @test.syskit_run_planner_stub? - root_tasks = @planning_tasks.map(&:planned_task) + root_tasks = resolution_results.instances.keys.map(&:planned_task) stub_network = StubNetwork.new(@test) # NOTE: this is a run-planner equivalent to syskit_stub_network diff --git a/testfile b/testfile new file mode 100644 index 000000000..e69de29bb