TimeControl
Constants
VERSION = "0.1.0"
Class methods
control
Enables virtual time control for the duration of the block.
Intercepts sleep, select ... when timeout(...),
Time.utc, and Time.instant so that time stands still until
explicitly advanced via Controller#advance.
IO operation timeouts (e.g. read_timeout, write_timeout) are also
intercepted on builds that use the Polling event loop (kqueue on macOS/BSD,
epoll on Linux). They are not intercepted on LibEvent or IOCP builds.
An optional start_time sets the initial value of Time.utc inside the
block. Without it, virtual UTC starts at the real wall-clock time.
TimeControl.control do |controller|
spawn { sleep 5.minutes; puts "done" }
controller.advance(5.minutes)
end
TimeControl.control(Time.utc(2030, 1, 1)) do |controller|
Time.utc.year # => 2030
end
TimeControl.control("2030-01-01T09:00:00Z") do |controller|
Time.utc.hour # => 9
end