class Dynflow::Testing::ManagedClock

Attributes

pending_pings[R]

Public Class Methods

new() click to toggle source
# File lib/dynflow/testing/managed_clock.rb, line 9
def initialize
  @pending_pings = []
end

Public Instance Methods

clear() click to toggle source
# File lib/dynflow/testing/managed_clock.rb, line 39
def clear
  @pending_pings.clear
end
current_time() click to toggle source
# File lib/dynflow/testing/managed_clock.rb, line 35
def current_time
  @current_time ||= Time.now
end
ping(who, time, with_what = nil, where = :<<) click to toggle source
# File lib/dynflow/testing/managed_clock.rb, line 13
def ping(who, time, with_what = nil, where = :<<)
  time = current_time + time if time.is_a? Numeric
  with = with_what.nil? ? None : Some[Object][with_what]
  @pending_pings << Clock::Timer[who, time, with, where]
  @pending_pings.sort!
end
progress(ignored_subjects = []) click to toggle source
# File lib/dynflow/testing/managed_clock.rb, line 20
def progress(ignored_subjects = [])
  if next_ping = @pending_pings.shift
    if !next_ping.what.respond_to?(:value) || !ignored_subjects.include?(next_ping.what.value)
      # we are testing an isolated system = we can move in time
      # without actually waiting
      @current_time = next_ping.when
      next_ping.apply
    end
  end
end
progress_all(ignored_subjects = []) click to toggle source
# File lib/dynflow/testing/managed_clock.rb, line 31
def progress_all(ignored_subjects = [])
  progress(ignored_subjects) until @pending_pings.empty?
end