Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/BaseJsTest.h

Issue 29499583: Issue 4938 - fix race conditions related to LazyFileSystem (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 27, 2017, 8:53 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/BaseJsTest.cpp » ('j') | test/FilterEngine.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/BaseJsTest.h
diff --git a/test/BaseJsTest.h b/test/BaseJsTest.h
index 522267058338b360d3befda28e1d3ba6bb7174cd..ddc28a4fe974dcda3b435116d4c886c7bd4b1ad8 100644
--- a/test/BaseJsTest.h
+++ b/test/BaseJsTest.h
@@ -149,94 +149,79 @@ public:
}
};
-class LazyFileSystem : public AdblockPlus::IFileSystem, public AdblockPlus::FileSystem
+class LazyFileSystem : public AdblockPlus::IFileSystem
{
public:
- IOBuffer Read(const std::string& path) const
+ typedef std::function<void()> Task;
+ typedef std::function<void(const Task& task)> Scheduler;
+ static void ExecuteImmediately(const Task& task)
{
- std::string dummyData("");
- if (path == "patterns.ini")
- dummyData = "# Adblock Plus preferences\n[Subscription]\nurl=~fl~";
- else if (path == "prefs.json")
- dummyData = "{}";
- return IOBuffer(dummyData.cbegin(), dummyData.cend());
+ if (task)
+ task();
}
-
- void Read(const std::string& path, const ReadCallback& callback) const
+ explicit LazyFileSystem(const Scheduler& scheduler = LazyFileSystem::ExecuteImmediately)
+ : scheduler(scheduler)
{
- std::thread([this, path, callback]
- {
- auto data = Read(path);
- callback(std::move(data), "");
- }).detach();
}
- void Write(const std::string& path, const IOBuffer& content)
+ void Read(const std::string& path, const ReadCallback& callback) const override
{
+ scheduler([path, callback]
+ {
+ if (path == "patterns.ini")
+ {
+ std::string dummyData = "# Adblock Plus preferences\n[Subscription]\nurl=~fl~";
+ callback(IOBuffer(dummyData.cbegin(), dummyData.cend()), "");
+ }
+ else if (path == "prefs.json")
+ {
+ std::string dummyData = "{}";
+ callback(IOBuffer(dummyData.cbegin(), dummyData.cend()), "");
+ }
+ });
}
void Write(const std::string& path, const IOBuffer& data,
- const Callback& callback)
+ const Callback& callback) override
{
- std::thread([this, path, data, callback]
- {
- Write(path, data);
- callback("");
- }).detach();
}
- void Move(const std::string& fromPath, const std::string& toPath)
- {
- }
void Move(const std::string& fromPath, const std::string& toPath,
- const Callback& callback)
- {
- std::thread([this, fromPath, toPath, callback]
- {
- Move(fromPath, toPath);
- callback("");
- }).detach();
- }
-
- void Remove(const std::string& path)
+ const Callback& callback) override
{
}
- void Remove(const std::string& path, const Callback& callback)
+ void Remove(const std::string& path, const Callback& callback) override
{
- std::thread([this, path, callback]
- {
- Remove(path);
- callback("");
- }).detach();
}
- StatResult Stat(const std::string& path) const
- {
- StatResult result;
- if (path == "patterns.ini")
- {
- result.exists = true;
- result.isFile = true;
- }
- return result;
- }
-
- void Stat(const std::string& path, const StatCallback& callback) const
+ void Stat(const std::string& path, const StatCallback& callback) const override
{
- std::thread([this, path, callback]
+ scheduler([path, callback]
{
- callback(Stat(path), "");
- }).detach();
+ StatResult result;
+ if (path == "patterns.ini")
+ {
+ result.exists = true;
+ result.isFile = true;
+ }
+ callback(result, "");
+ });
}
- std::string Resolve(const std::string& path) const
+ std::string Resolve(const std::string& path) const override
{
return path;
}
+public:
+ Scheduler scheduler;
};
+AdblockPlus::FilterEnginePtr CreateFilterEngine(LazyFileSystem& fileSystem,
+ const AdblockPlus::JsEnginePtr& jsEngine,
+ const AdblockPlus::FilterEngine::CreationParameters& creationParams = AdblockPlus::FilterEngine::CreationParameters());
+
class NoopWebRequest : public AdblockPlus::IWebRequest
{
public:
« no previous file with comments | « no previous file | test/BaseJsTest.cpp » ('j') | test/FilterEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld