local cfg = dstest.config({
substrate = "docker",
seed = 0xC10C,
})
local s = dstest.setup(cfg, {
image = "kennethreitz/httpbin",
ports = { 80 },
clock = { virtual = true, start_epoch = 1577836800 }, })
local vc = dstest.clock.virtual(s)
dstest.info("virtual clock created; waking subject...")
dstest.exec(s, { "sleep", "1" })
local function log_virtual(label)
local t = vc:now()
dstest.info(string.format("%-22s virtual=%.3fs (epoch ms %d)", label, t.secs, t.millis))
end
local function plan()
return coroutine.wrap(function()
coroutine.yield("initial", function() end)
coroutine.yield("advance +5s", function() vc:advance(5000) end)
coroutine.yield("offset +1h", function() vc:set_offset(3600000) end)
coroutine.yield("freeze", function() vc:freeze() end)
end)
end
for label, action in plan() do
action()
log_virtual(label)
end
local st = vc:state()
dstest.info(string.format(
"state: virtualised=%s epoch=%d offset=%dms rate=%.1fx frozen=%s",
tostring(st.virtualised), st.epoch_millis, st.offset_millis,
st.rate, tostring(st.frozen)
))
local st_end = vc:state()
assert(st_end.epoch_millis >= 1577836800000, "virtual clock did not advance")
dstest.dst.clear(s)
dstest.info("clock example complete")