 Issue 29367522:
  Issue #4688, #3595 - Web request use scheduled threads; unit tests terminate
    
  
    Issue 29367522:
  Issue #4688, #3595 - Web request use scheduled threads; unit tests terminate 
  | Index: test/BaseJsTest.h | 
| =================================================================== | 
| --- a/test/BaseJsTest.h | 
| +++ b/test/BaseJsTest.h | 
| @@ -18,6 +18,8 @@ | 
| #ifndef MOCKS_H | 
| #define MOCKS_H | 
| +#include <condition_variable> | 
| +#include <mutex> | 
| #include <thread> | 
| #include <AdblockPlus.h> | 
| @@ -119,15 +121,49 @@ | 
| } | 
| }; | 
| +class LazyWaiter | 
| +{ | 
| + std::mutex m; | 
| + typedef std::unique_lock<std::mutex> UniqueLockType; | 
| + std::condition_variable cv; | 
| + bool running; | 
| + | 
| +public: | 
| + LazyWaiter() | 
| + : running(true) | 
| + {} | 
| + | 
| + void WaitUntilCancelled() | 
| + { | 
| + UniqueLockType ul(m); | 
| + cv.wait(ul, [this]() -> bool { return !running; }); | 
| + } | 
| + | 
| + void Cancel() | 
| + { | 
| + UniqueLockType ul(m); | 
| + running = false; | 
| + cv.notify_all(); | 
| + } | 
| +}; | 
| + | 
| class LazyWebRequest : public AdblockPlus::WebRequest | 
| { | 
| + mutable LazyWaiter w; | 
| 
Eric
2016/12/14 20:53:55
Declared mutable because `GET()` is declared `cons
 | 
| + | 
| public: | 
| + LazyWebRequest() {} // = default; | 
| + | 
| AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders) const | 
| { | 
| - while (true) | 
| - std::this_thread::sleep_for(std::chrono::seconds(100)); | 
| + w.WaitUntilCancelled(); | 
| return AdblockPlus::ServerResponse(); | 
| } | 
| + | 
| + void Cancel() | 
| + { | 
| + w.Cancel(); | 
| + } | 
| }; | 
| class LazyLogSystem : public AdblockPlus::LogSystem |