Skip to content

Commit

Permalink
fix: add more information on the network generation application result
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhonasiv committed Feb 26, 2025
1 parent 4eeefa1 commit 3b564b1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
3 changes: 0 additions & 3 deletions lib/syskit/network_generation/async.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/syskit/network_generation/resolution_error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/syskit/network_generation/system_network_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions lib/syskit/runtime/apply_requirement_modifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions lib/syskit/test/instance_requirement_planning_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added testfile
Empty file.

0 comments on commit 3b564b1

Please sign in to comment.