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

Unified Diff: test/UpdateCheck.cpp

Issue 29372702: Issue #4826 - Use latch to replace thread-sleeping in tests
Patch Set: Created Jan. 19, 2017, 5:56 p.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
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);

Powered by Google App Engine
This is Rietveld