Index: test/UpdateCheck.cpp |
=================================================================== |
--- a/test/UpdateCheck.cpp |
+++ b/test/UpdateCheck.cpp |
@@ -18,6 +18,7 @@ |
#include <functional> |
#include "BaseJsTest.h" |
+#include "JsLatch.h" |
#include "../src/JsEngineTransition.h" |
namespace |
@@ -100,10 +101,15 @@ |
Construct(); |
} |
- void ForceUpdateCheck() |
+ void ForceUpdateCheckSynchronous() |
{ |
- filterEngine->ForceUpdateCheck( |
- std::bind(&UpdateCheckTest::UpdateCallback, this, std::placeholders::_1)); |
+ Latch latch(1); |
+ filterEngine->ForceUpdateCheck([&, this](const std::string& error) -> void |
+ { |
+ UpdateCallback(error); |
+ latch.Arrive(); |
+ }); |
+ latch.Wait(); |
} |
void EventCallback(AdblockPlus::JsValueList& params) |
@@ -131,9 +137,7 @@ |
appInfo.developmentBuild = false; |
Reset(); |
- ForceUpdateCheck(); |
- |
- std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
+ ForceUpdateCheckSynchronous(); |
ASSERT_FALSE(eventCallbackCalled); |
ASSERT_TRUE(updateCallbackCalled); |
@@ -168,9 +172,7 @@ |
appInfo.developmentBuild = true; |
Reset(); |
- ForceUpdateCheck(); |
- |
- std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
+ ForceUpdateCheckSynchronous(); |
ASSERT_TRUE(eventCallbackCalled); |
ASSERT_EQ(1u, eventCallbackParams.size()); |
@@ -207,9 +209,7 @@ |
appInfo.developmentBuild = true; |
Reset(); |
- ForceUpdateCheck(); |
- |
- std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
+ ForceUpdateCheckSynchronous(); |
ASSERT_TRUE(eventCallbackCalled); |
ASSERT_EQ(1u, eventCallbackParams.size()); |
@@ -231,9 +231,7 @@ |
appInfo.developmentBuild = true; |
Reset(); |
- ForceUpdateCheck(); |
- |
- std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
+ ForceUpdateCheckSynchronous(); |
ASSERT_FALSE(eventCallbackCalled); |
ASSERT_TRUE(updateCallbackCalled); |
@@ -253,9 +251,7 @@ |
appInfo.developmentBuild = true; |
Reset(); |
- ForceUpdateCheck(); |
- |
- std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
+ ForceUpdateCheckSynchronous(); |
ASSERT_FALSE(eventCallbackCalled); |
ASSERT_TRUE(updateCallbackCalled); |
@@ -275,9 +271,7 @@ |
appInfo.developmentBuild = true; |
Reset(); |
- ForceUpdateCheck(); |
- |
- std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
+ ForceUpdateCheckSynchronous(); |
ASSERT_FALSE(eventCallbackCalled); |
ASSERT_TRUE(updateCallbackCalled); |