From 5cb6ff7dd33def973740cc5cbf14a3c3bd31c028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 24 Oct 2020 17:03:01 +0200 Subject: [PATCH] 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). --- tests/0-dirwatcher-rec.d | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/tests/0-dirwatcher-rec.d b/tests/0-dirwatcher-rec.d index d6b9538..74ad08e 100644 --- a/tests/0-dirwatcher-rec.d +++ b/tests/0-dirwatcher-rec.d @@ -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) @@ -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); @@ -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.");