Fix recursive directory watcher test.

Was storing stack allocated strings, as well as not skipping all directory change events (which now is important on Linux/inotify).
This commit is contained in:
Sönke Ludwig 2020-10-24 17:03:01 +02:00
parent 4803399376
commit 5cb6ff7dd3

View file

@ -80,6 +80,8 @@ void testCallback(WatcherID w, in ref FileChange ch)
@safe nothrow { @safe nothrow {
assert(w == watcher, "Wrong watcher generated a change"); assert(w == watcher, "Wrong watcher generated a change");
pendingChanges ~= ch; pendingChanges ~= ch;
// the name is accesible scope-only!
pendingChanges[$-1].name = pendingChanges[$-1].name.dup;
} }
void dropChanges(Duration dur) void dropChanges(Duration dur)
@ -101,8 +103,27 @@ void dropChanges(Duration dur)
pendingChanges = null; pendingChanges = null;
} }
void skipDirectoryChanges()
{
// ignore different directory modification notifications on Windows as
// opposed to the other systems
while (pendingChanges.length) {
auto pch = pendingChanges[0];
if (pch.kind == FileChangeKind.modified) {
auto p = buildPath(pch.baseDirectory, pch.directory, pch.name);
if (!exists(p) || isDir(p)) {
pendingChanges = pendingChanges[1 .. $];
continue;
}
}
break;
}
}
void expectChange(FileChange ch, bool expect_change) void expectChange(FileChange ch, bool expect_change)
{ {
skipDirectoryChanges();
auto starttime = MonoTime.currTime(); auto starttime = MonoTime.currTime();
again: while (!pendingChanges.length) { again: while (!pendingChanges.length) {
auto er = eventDriver.core.processEvents(100.msecs); auto er = eventDriver.core.processEvents(100.msecs);
@ -121,19 +142,7 @@ void expectChange(FileChange ch, bool expect_change)
return; return;
} }
// ignore different directory modification notifications on Windows as skipDirectoryChanges();
// opposed to the other systems
while (pendingChanges.length) {
auto pch = pendingChanges[0];
if (pch.kind == FileChangeKind.modified) {
auto p = buildPath(pch.baseDirectory, pch.directory, pch.name);
if (!exists(p) || isDir(p)) {
pendingChanges = pendingChanges[1 .. $];
continue;
}
}
break;
}
} }
assert(expect_change, "Got change although none was expected."); assert(expect_change, "Got change although none was expected.");