Class: Dynflow::Testing::ManagedClock
- Inherits:
-
Object
- Object
- Dynflow::Testing::ManagedClock
- Includes:
- Algebrick::Types
- Defined in:
- lib/dynflow/testing/managed_clock.rb
Instance Attribute Summary collapse
-
#pending_pings ⇒ Object
readonly
Returns the value of attribute pending_pings.
Instance Method Summary collapse
- #clear ⇒ Object
- #current_time ⇒ Object
-
#initialize ⇒ ManagedClock
constructor
A new instance of ManagedClock.
- #ping(who, time, with_what = nil, where = :<<) ⇒ Object
- #progress(ignored_subjects = []) ⇒ Object
- #progress_all(ignored_subjects = []) ⇒ Object
Constructor Details
#initialize ⇒ ManagedClock
Returns a new instance of ManagedClock.
10 11 12 |
# File 'lib/dynflow/testing/managed_clock.rb', line 10 def initialize @pending_pings = [] end |
Instance Attribute Details
#pending_pings ⇒ Object (readonly)
Returns the value of attribute pending_pings.
6 7 8 |
# File 'lib/dynflow/testing/managed_clock.rb', line 6 def pending_pings @pending_pings end |
Instance Method Details
#clear ⇒ Object
40 41 42 |
# File 'lib/dynflow/testing/managed_clock.rb', line 40 def clear @pending_pings.clear end |
#current_time ⇒ Object
36 37 38 |
# File 'lib/dynflow/testing/managed_clock.rb', line 36 def current_time @current_time ||= Time.now end |
#ping(who, time, with_what = nil, where = :<<) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/dynflow/testing/managed_clock.rb', line 14 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 = []) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dynflow/testing/managed_clock.rb', line 21 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 = []) ⇒ Object
32 33 34 |
# File 'lib/dynflow/testing/managed_clock.rb', line 32 def progress_all(ignored_subjects = []) progress(ignored_subjects) until @pending_pings.empty? end |