Skip to content

Commit

Permalink
Fix recursive directory watcher test.
Browse files Browse the repository at this point in the history
Was storing stack allocated strings, as well as not skipping all directory change events (which now is important on Linux/inotify).
  • Loading branch information
s-ludwig committed Oct 24, 2020
1 parent 4803399 commit 5cb6ff7
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions tests/0-dirwatcher-rec.d
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ void testCallback(WatcherID w, in ref FileChange ch)
@safe nothrow {
assert(w == watcher, "Wrong watcher generated a change");
pendingChanges ~= ch;
// the name is accesible scope-only!
pendingChanges[$-1].name = pendingChanges[$-1].name.dup;
}

void dropChanges(Duration dur)
Expand All @@ -101,8 +103,27 @@ void dropChanges(Duration dur)
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)
{
skipDirectoryChanges();

auto starttime = MonoTime.currTime();
again: while (!pendingChanges.length) {
auto er = eventDriver.core.processEvents(100.msecs);
Expand All @@ -121,19 +142,7 @@ void expectChange(FileChange ch, bool expect_change)
return;
}

// 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;
}
skipDirectoryChanges();
}
assert(expect_change, "Got change although none was expected.");

Expand Down

0 comments on commit 5cb6ff7

Please sign in to comment.