Work around platform differences in the directory watcher test.
- Drops all events that happen before any changes are made (FSEventStream reports events from the past to a certain degree) - Tests the same file twice in a row, since FSEventStream might coalesce events and report bogus changes - Allows "modified" instead of "added" events, because FSEventStream does not allow to distinguish in some cases
This commit is contained in:
parent
e28450f9f5
commit
6e5fb79c62
|
@ -35,13 +35,15 @@ void main()
|
||||||
// test non-recursive watcher
|
// test non-recursive watcher
|
||||||
watcher = eventDriver.watchers.watchDirectory(testDir, false, toDelegate(&testCallback));
|
watcher = eventDriver.watchers.watchDirectory(testDir, false, toDelegate(&testCallback));
|
||||||
assert(watcher != WatcherID.invalid);
|
assert(watcher != WatcherID.invalid);
|
||||||
Thread.sleep(400.msecs); // some watcher implementations need time to initialize
|
// some watcher implementations need time to initialize or report past events
|
||||||
|
dropChanges(2000.msecs);
|
||||||
testFile( "file1.dat");
|
testFile( "file1.dat");
|
||||||
testFile( "file2.dat");
|
testFile( "file2.dat");
|
||||||
testFile( "dira/file1.dat", false);
|
testFile( "dira/file1.dat", false);
|
||||||
testCreateDir("dirb");
|
testCreateDir("dirb");
|
||||||
testFile( "dirb/file1.dat", false);
|
testFile( "dirb/file1.dat", false);
|
||||||
testRemoveDir("dirb");
|
testRemoveDir("dirb");
|
||||||
|
testFile( "file1.dat");
|
||||||
eventDriver.watchers.releaseRef(watcher);
|
eventDriver.watchers.releaseRef(watcher);
|
||||||
testFile( "file1.dat", false);
|
testFile( "file1.dat", false);
|
||||||
testRemoveDir("dira", false);
|
testRemoveDir("dira", false);
|
||||||
|
@ -50,7 +52,8 @@ void main()
|
||||||
// test recursive watcher
|
// test recursive watcher
|
||||||
watcher = eventDriver.watchers.watchDirectory(testDir, true, toDelegate(&testCallback));
|
watcher = eventDriver.watchers.watchDirectory(testDir, true, toDelegate(&testCallback));
|
||||||
assert(watcher != WatcherID.invalid);
|
assert(watcher != WatcherID.invalid);
|
||||||
Thread.sleep(400.msecs); // some watcher implementations need time to initialize
|
// some watcher implementations need time to initialize or report past events
|
||||||
|
dropChanges(2000.msecs);
|
||||||
testFile( "file1.dat");
|
testFile( "file1.dat");
|
||||||
testFile( "file2.dat");
|
testFile( "file2.dat");
|
||||||
testFile( "dira/file1.dat");
|
testFile( "dira/file1.dat");
|
||||||
|
@ -58,6 +61,7 @@ void main()
|
||||||
testFile( "dirb/file1.dat");
|
testFile( "dirb/file1.dat");
|
||||||
testRename( "dirb", "dirc");
|
testRename( "dirb", "dirc");
|
||||||
testFile( "dirc/file2.dat");
|
testFile( "dirc/file2.dat");
|
||||||
|
testFile( "file1.dat");
|
||||||
eventDriver.watchers.releaseRef(watcher);
|
eventDriver.watchers.releaseRef(watcher);
|
||||||
testFile( "file1.dat", false);
|
testFile( "file1.dat", false);
|
||||||
testFile( "dira/file1.dat", false);
|
testFile( "dira/file1.dat", false);
|
||||||
|
@ -78,11 +82,30 @@ void testCallback(WatcherID w, in ref FileChange ch)
|
||||||
pendingChanges ~= ch;
|
pendingChanges ~= ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dropChanges(Duration dur)
|
||||||
|
{
|
||||||
|
auto starttime = MonoTime.currTime();
|
||||||
|
auto remdur = dur;
|
||||||
|
while (remdur > 0.msecs) {
|
||||||
|
auto er = eventDriver.core.processEvents(remdur);
|
||||||
|
switch (er) {
|
||||||
|
default: assert(false, format("Unexpected event loop exit code: %s", er));
|
||||||
|
case ExitReason.idle: break;
|
||||||
|
case ExitReason.timeout: break;
|
||||||
|
case ExitReason.outOfWaiters:
|
||||||
|
assert(false, "No watcher left, but expected change.");
|
||||||
|
}
|
||||||
|
remdur = dur - (MonoTime.currTime() - starttime);
|
||||||
|
}
|
||||||
|
|
||||||
|
pendingChanges = null;
|
||||||
|
}
|
||||||
|
|
||||||
void expectChange(FileChange ch, bool expect_change)
|
void expectChange(FileChange ch, bool expect_change)
|
||||||
{
|
{
|
||||||
auto starttime = MonoTime.currTime();
|
auto starttime = MonoTime.currTime();
|
||||||
again: while (!pendingChanges.length) {
|
again: while (!pendingChanges.length) {
|
||||||
auto er = eventDriver.core.processEvents(10.msecs);
|
auto er = eventDriver.core.processEvents(100.msecs);
|
||||||
switch (er) {
|
switch (er) {
|
||||||
default: assert(false, format("Unexpected event loop exit code: %s", er));
|
default: assert(false, format("Unexpected event loop exit code: %s", er));
|
||||||
case ExitReason.idle: break;
|
case ExitReason.idle: break;
|
||||||
|
@ -123,9 +146,12 @@ void expectChange(FileChange ch, bool expect_change)
|
||||||
if (pch.kind == FileChangeKind.modified && (pch.name == "dira" || pch.name == "dirb"))
|
if (pch.kind == FileChangeKind.modified && (pch.name == "dira" || pch.name == "dirb"))
|
||||||
goto again;
|
goto again;
|
||||||
|
|
||||||
// test all field excep the isDir one, which does not work on all systems
|
// test all field except the isDir one, which does not work on all systems
|
||||||
assert(pch.kind == ch.kind && pch.baseDirectory == ch.baseDirectory &&
|
// we allow "modified" instead of "added" here, as the FSEvents based watcher
|
||||||
pch.directory == ch.directory && pch.name == ch.name,
|
// has strange results on the CI VM
|
||||||
|
assert((pch.kind == ch.kind || pch.kind == FileChangeKind.modified && ch.kind == FileChangeKind.added)
|
||||||
|
&& pch.baseDirectory == ch.baseDirectory
|
||||||
|
&& pch.directory == ch.directory && pch.name == ch.name,
|
||||||
format("Unexpected change: %s vs %s", pch, ch));
|
format("Unexpected change: %s vs %s", pch, ch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue