Tests should use monotonic clock too for timeout
This commit is contained in:
parent
3b6b2ab900
commit
9015f065c5
|
@ -7,7 +7,7 @@ module test;
|
||||||
import eventcore.core;
|
import eventcore.core;
|
||||||
import eventcore.internal.utils : print;
|
import eventcore.internal.utils : print;
|
||||||
import core.thread : Thread;
|
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.file : exists, remove, rename, rmdirRecurse, mkdir;
|
||||||
import std.format : format;
|
import std.format : format;
|
||||||
import std.functional : toDelegate;
|
import std.functional : toDelegate;
|
||||||
|
@ -80,9 +80,7 @@ void testCallback(WatcherID w, in ref FileChange ch)
|
||||||
|
|
||||||
void expectChange(FileChange ch, bool expect_change)
|
void expectChange(FileChange ch, bool expect_change)
|
||||||
{
|
{
|
||||||
import std.datetime : Clock, UTC;
|
auto starttime = MonoTime.currTime();
|
||||||
|
|
||||||
auto starttime = Clock.currTime(UTC());
|
|
||||||
again: while (!pendingChanges.length) {
|
again: while (!pendingChanges.length) {
|
||||||
auto er = eventDriver.core.processEvents(10.msecs);
|
auto er = eventDriver.core.processEvents(10.msecs);
|
||||||
switch (er) {
|
switch (er) {
|
||||||
|
@ -95,7 +93,7 @@ void expectChange(FileChange ch, bool expect_change)
|
||||||
assert(!expect_change, "No watcher left, but expected change.");
|
assert(!expect_change, "No watcher left, but expected change.");
|
||||||
return;
|
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));
|
assert(!expect_change, format("Got no change, expected %s.", ch));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,16 @@
|
||||||
module test;
|
module test;
|
||||||
|
|
||||||
import eventcore.core;
|
import eventcore.core;
|
||||||
import std.datetime : Clock, SysTime, UTC;
|
import core.time : Duration, MonoTime, msecs;
|
||||||
import std.stdio : writefln;
|
import std.stdio : writefln;
|
||||||
import core.time : Duration, msecs;
|
|
||||||
|
|
||||||
SysTime s_startTime;
|
MonoTime s_startTime;
|
||||||
int s_cnt = 0;
|
int s_cnt = 0;
|
||||||
bool s_done;
|
bool s_done;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
s_startTime = Clock.currTime(UTC());
|
s_startTime = MonoTime.currTime();
|
||||||
|
|
||||||
auto tm = eventDriver.timers.create();
|
auto tm = eventDriver.timers.create();
|
||||||
eventDriver.timers.wait(tm, (tm) nothrow @safe {
|
eventDriver.timers.wait(tm, (tm) nothrow @safe {
|
||||||
|
@ -23,7 +22,7 @@ void main()
|
||||||
|
|
||||||
{
|
{
|
||||||
scope (failure) assert(false);
|
scope (failure) assert(false);
|
||||||
dur = Clock.currTime(UTC()) - s_startTime;
|
dur = MonoTime.currTime() - s_startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -37,7 +36,7 @@ void main()
|
||||||
|
|
||||||
void secondTier(TimerID timer) nothrow @safe {
|
void secondTier(TimerID timer) nothrow @safe {
|
||||||
try {
|
try {
|
||||||
auto dur = Clock.currTime(UTC()) - s_startTime;
|
auto dur = MonoTime.currTime() - s_startTime;
|
||||||
s_cnt++;
|
s_cnt++;
|
||||||
assert(dur > 300.msecs * s_cnt, (dur - 300.msecs * s_cnt).toString());
|
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());
|
assert(dur < 300.msecs * s_cnt + 100.msecs, (dur - 300.msecs * s_cnt).toString());
|
||||||
|
|
|
@ -5,17 +5,16 @@
|
||||||
module test;
|
module test;
|
||||||
|
|
||||||
import eventcore.core;
|
import eventcore.core;
|
||||||
import std.datetime : Clock, SysTime, UTC;
|
import core.time : Duration, MonoTime, msecs;
|
||||||
import std.stdio : writefln;
|
import std.stdio : writefln;
|
||||||
import core.time : Duration, msecs;
|
|
||||||
|
|
||||||
SysTime s_startTime;
|
MonoTime s_startTime;
|
||||||
int s_cnt = 0;
|
int s_cnt = 0;
|
||||||
bool s_done;
|
bool s_done;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
s_startTime = Clock.currTime(UTC());
|
s_startTime = MonoTime.currTime();
|
||||||
|
|
||||||
bool timer1fired = false;
|
bool timer1fired = false;
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ void main()
|
||||||
eventDriver.timers.wait(tm, (tm) nothrow @safe {
|
eventDriver.timers.wait(tm, (tm) nothrow @safe {
|
||||||
try {
|
try {
|
||||||
writefln("First timer");
|
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 >= 1200.msecs, (dur - 1200.msecs).toString());
|
||||||
assert(dur < 1300.msecs, (dur - 1200.msecs).toString());
|
assert(dur < 1300.msecs, (dur - 1200.msecs).toString());
|
||||||
|
@ -43,7 +42,7 @@ void main()
|
||||||
try {
|
try {
|
||||||
writefln("Second timer");
|
writefln("Second timer");
|
||||||
|
|
||||||
auto dur = Clock.currTime(UTC()) - s_startTime;
|
auto dur = MonoTime.currTime() - s_startTime;
|
||||||
s_cnt++;
|
s_cnt++;
|
||||||
assert(dur > 300.msecs * s_cnt, (dur - 300.msecs * s_cnt).toString());
|
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());
|
assert(dur < 300.msecs * s_cnt + 100.msecs, (dur - 300.msecs * s_cnt).toString());
|
||||||
|
|
Loading…
Reference in a new issue