Given(/^I have a running auton with one defined step without any parameters$/) do class SimpleAuton include StructureMapper::Hash def start 'ok' end attribute foo: String end @auton_type="SimpleAuton" @auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type @expected_result = "ok" end When(/^I add the step to the execution queue$/) do @step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :start end When(/^I wait for the step to execute$/) do begin @execution_result = Celluloid::Actor[:nestene_core].wait_for_execution_result(@auton_id, @step_execution_id) rescue Exception => e @execution_exception = e end end Then(/^the execution result should be returned$/) do expect(@execution_result).to eq(@expected_result) end Given(/^I have a running auton with one defined step with parameters$/) do class SimpleParamsAuton include StructureMapper::Hash def start(p1) 'param: %s' % p1 end attribute foo: String end @auton_type="SimpleParamsAuton" @auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type @expected_result = "param: p1" end When(/^I add the step with parameters to the execution queue$/) do @step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :start, "p1" end Given(/^I have a running auton with one defined step that fails$/) do class SimpleFailingAuton include StructureMapper::Hash def start raise "failed!" end attribute foo: String end @auton_type="SimpleFailingAuton" @auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type end Then(/^the auton should be in the FAILED state$/) do expect(Celluloid::Actor["storage:%s" % @auton_id].get.state).to eq(:failed) end Then(/^the execution result should be an exception$/) do expect(@execution_exception).to be_a(Exception) end Given(/^I have a running auton with one defined step that fails and one that does not fail$/) do class SimpleTwoStepsFirstFailingAuton include StructureMapper::Hash def start raise "failed!" end def cont end attribute foo: String end @auton_type="SimpleTwoStepsFirstFailingAuton" @auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type end When(/^I add first the failing and then the not failing step to the execution queue$/) do @first_step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :start @second_step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :cont end When(/^I wait for the first step to execute$/) do begin @execution_result = Celluloid::Actor[:nestene_core].wait_for_execution_result(@auton_id, @first_step_execution_id) rescue Exception => e @execution_exception = e end end Then(/^the not failing step will not be executed$/) do sleep 0.1 expect(Celluloid::Actor["storage:%s" % @auton_id].get.queue.to_execute.first.uuid).to eq(@second_step_execution_id) end Given(/^I have a running auton with one defined step that fails on the first invocation but succeeds on the second$/) do class FirstExecutionFailingAuton include StructureMapper::Hash def initalize self.first = true end def start should_fail = self.first self.first = false raise "failed!" if should_fail end attribute first: Boolean end @auton_type="FirstExecutionFailingAuton" @auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type end When(/^I repeat the failed step$/) do @step_execution_id = Celluloid::Actor[:nestene_core].repeat_step @auton_id, @step_execution_id end When(/^I resume the failed auton$/) do @step_execution_id = Celluloid::Actor[:nestene_core].resume @auton_id end When(/^I wait for the second step to execute$/) do begin @execution_result = Celluloid::Actor[:nestene_core].wait_for_execution_result(@auton_id, @second_step_execution_id) rescue Exception => e @execution_exception = e end end Given(/^I have a running auton with one defined step that fails and one that does not fail and an exception handling method for the whole Auton$/) do class TwoStepsFirstFailingWithExceptionHandlerAuton include StructureMapper::Hash def start raise "failed!" end def cont end def handle_exception type, message, method_name, params end attribute foo: String end @auton_type="TwoStepsFirstFailingWithExceptionHandlerAuton" @auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type end Then(/^the "(.*?)" method should have been executed$/) do |method_name| expect(Celluloid::Actor["storage:%s" % @auton_id].get.queue.executed.map(&:name)).to include(method_name.to_sym) end