Tests should use monotonic clock too for timeout

This commit is contained in:
Hiroki Noda 2018-12-23 22:15:54 +09:00
parent 3b6b2ab900
commit 9015f065c5
3 changed files with 13 additions and 17 deletions

View file

@ -7,7 +7,7 @@ module test;
import eventcore.core;
import eventcore.internal.utils : print;
import core.thread : Thread;
import core.time : Duration, msecs;
import core.time : Duration, MonoTime, msecs;
import std.file : exists, remove, rename, rmdirRecurse, mkdir;
import std.format : format;
import std.functional : toDelegate;
@ -80,9 +80,7 @@ void testCallback(WatcherID w, in ref FileChange ch)
void expectChange(FileChange ch, bool expect_change)
{
import std.datetime : Clock, UTC;
auto starttime = Clock.currTime(UTC());
auto starttime = MonoTime.currTime();
again: while (!pendingChanges.length) {
auto er = eventDriver.core.processEvents(10.msecs);
switch (er) {
@ -95,7 +93,7 @@ void expectChange(FileChange ch, bool expect_change)
assert(!expect_change, "No watcher left, but expected change.");
return;
}
if (!pendingChanges.length && Clock.currTime(UTC()) - starttime >= 2000.msecs) {
if (!pendingChanges.length && MonoTime.currTime() - starttime >= 2000.msecs) {
assert(!expect_change, format("Got no change, expected %s.", ch));
return;
}

View file

@ -5,17 +5,16 @@
module test;
import eventcore.core;
import std.datetime : Clock, SysTime, UTC;
import core.time : Duration, MonoTime, msecs;
import std.stdio : writefln;
import core.time : Duration, msecs;
SysTime s_startTime;
MonoTime s_startTime;
int s_cnt = 0;
bool s_done;
void main()
{
s_startTime = Clock.currTime(UTC());
s_startTime = MonoTime.currTime();
auto tm = eventDriver.timers.create();
eventDriver.timers.wait(tm, (tm) nothrow @safe {
@ -23,7 +22,7 @@ void main()
{
scope (failure) assert(false);
dur = Clock.currTime(UTC()) - s_startTime;
dur = MonoTime.currTime() - s_startTime;
}
try {
@ -37,7 +36,7 @@ void main()
void secondTier(TimerID timer) nothrow @safe {
try {
auto dur = Clock.currTime(UTC()) - s_startTime;
auto dur = MonoTime.currTime() - s_startTime;
s_cnt++;
assert(dur > 300.msecs * s_cnt, (dur - 300.msecs * s_cnt).toString());
assert(dur < 300.msecs * s_cnt + 100.msecs, (dur - 300.msecs * s_cnt).toString());

View file

@ -5,17 +5,16 @@
module test;
import eventcore.core;
import std.datetime : Clock, SysTime, UTC;
import core.time : Duration, MonoTime, msecs;
import std.stdio : writefln;
import core.time : Duration, msecs;
SysTime s_startTime;
MonoTime s_startTime;
int s_cnt = 0;
bool s_done;
void main()
{
s_startTime = Clock.currTime(UTC());
s_startTime = MonoTime.currTime();
bool timer1fired = false;
@ -24,7 +23,7 @@ void main()
eventDriver.timers.wait(tm, (tm) nothrow @safe {
try {
writefln("First timer");
auto dur = Clock.currTime(UTC()) - s_startTime;
auto dur = MonoTime.currTime() - s_startTime;
assert(dur >= 1200.msecs, (dur - 1200.msecs).toString());
assert(dur < 1300.msecs, (dur - 1200.msecs).toString());
@ -43,7 +42,7 @@ void main()
try {
writefln("Second timer");
auto dur = Clock.currTime(UTC()) - s_startTime;
auto dur = MonoTime.currTime() - s_startTime;
s_cnt++;
assert(dur > 300.msecs * s_cnt, (dur - 300.msecs * s_cnt).toString());
assert(dur < 300.msecs * s_cnt + 100.msecs, (dur - 300.msecs * s_cnt).toString());