Given(/^an Auton that schedules an one off delayed step in (\d+)\.(\d+) second$/) do |arg1, arg2| class TimeDelayedStepSchedulingAuton include StructureMapper::Hash def first context.schedule_delayed_step(0.1, :second) end def second 'ok' end attr_accessor :context attribute foo: Fixnum end @auton_type="TimeDelayedStepSchedulingAuton" @auton_id = Celluloid::Actor[:nestene_core].create_auton(@auton_type) end When(/^I execute the step that schedules the delayed step$/) do @start_time = Time.now @step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :first @second_step_execution_id = Celluloid::Actor[:nestene_core].wait_for_execution_result(@auton_id, @step_execution_id) end Then(/^the elapsed time between first and sencond step should be at least (\d+\.\d+) secods$/) do |seconds_string| raise @execution_exception if @execution_exception expect(@execution_result).to eq('ok') expect(Time.now - @start_time).to be >= seconds_string.to_f end When(/^I cancel the time delayed step$/) do Celluloid::Actor[:nestene_core].cancel_delayed_step @auton_id, @second_step_execution_id end When(/^I wait for (\d+\.\d+) seconds$/) do |seconds| sleep seconds.to_f end Then(/^the scheduled step should not be executed$/) do expect(Celluloid::Actor[:nestene_core].get_state(@auton_id).queue.executed.size).to eq(1) end Given(/^an Auton that schedules an repeating every (\d+\.\d+) seconds delayed step in (\d+\.\d+) second$/) do |every, delay| class RepeatingTimeDelayedStepdSchedulingAuton include StructureMapper::Hash def first context.schedule_repeating_delayed_step(0.1, 0.1, :second) end def second 'ok' end attr_accessor :context attribute foo: Fixnum end @auton_type="RepeatingTimeDelayedStepdSchedulingAuton" @auton_id = Celluloid::Actor[:nestene_core].create_auton(@auton_type) end Then(/^the scheduled step should be executed twice$/) do expect(Celluloid::Actor[:nestene_core].get_state(@auton_id).queue.executed.map{|m| m.name}).to eq([:first,:second,:second]) end Given(/^an Auton that schedules an one off delayed step in (\d+\.\d+) seconds and has a failing step$/) do |delay| class TimeDelayedAndFailingStepSchedulingAuton include StructureMapper::Hash def first context.schedule_delayed_step(0.1, :second) end def fail raise "fail!" end def second 'ok' end attr_accessor :context attribute foo: Fixnum end @auton_type="TimeDelayedAndFailingStepSchedulingAuton" @auton_id = Celluloid::Actor[:nestene_core].create_auton(@auton_type) end When(/^I execute the failing step$/) do @step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :fail expect {Celluloid::Actor[:nestene_core].wait_for_execution_result(@auton_id, @step_execution_id)}.to raise_error end Then(/^the delayed step should not be executed$/) do expect(Celluloid::Actor[:nestene_core].get_state(@auton_id).queue.executed.map{|m| m.name}).to eq([:first,:fail]) end