Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: base/mac/libdispatch_task_runner_unittest.cc

Issue 11547006: De-flake the LibDispatchTaskRunner tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove circular reference Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/mac/libdispatch_task_runner.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mac/libdispatch_task_runner_unittest.cc
diff --git a/base/mac/libdispatch_task_runner_unittest.cc b/base/mac/libdispatch_task_runner_unittest.cc
index abd8c30835fde46d46a345bf8de25582afe5bc74..c3488d275861564cdb737552ec0c64c8d6ed358f 100644
--- a/base/mac/libdispatch_task_runner_unittest.cc
+++ b/base/mac/libdispatch_task_runner_unittest.cc
@@ -24,6 +24,7 @@ class LibDispatchTaskRunnerTest : public testing::Test {
(&message_loop_)->PostTask(FROM_HERE, MessageLoop::QuitClosure());
});
message_loop_.Run();
+ task_runner_->Shutdown();
}
// VerifyTaskOrder takes the expectations from TaskOrderMarkers and compares
@@ -34,7 +35,7 @@ class LibDispatchTaskRunnerTest : public testing::Test {
for (size_t i = 0; i < num_expectations; ++i) {
if (i >= actual_size) {
- EXPECT_LT(i, actual_size) << "Expected " << expectations[i];
+ EXPECT_LE(i, actual_size) << "Expected " << expectations[i];
continue;
}
@@ -126,17 +127,15 @@ TEST_F(LibDispatchTaskRunnerTest, NoMessageLoop) {
VerifyTaskOrder(expectations, arraysize(expectations));
}
-// This test is flaky, see http://crbug.com/165117.
-TEST_F(LibDispatchTaskRunnerTest, FLAKY_DispatchAndPostTasks) {
+TEST_F(LibDispatchTaskRunnerTest, DispatchAndPostTasks) {
dispatch_async(task_runner_->GetDispatchQueue(), ^{
TaskOrderMarker marker(this, "First Block");
- task_runner_->PostTask(FROM_HERE,
- BoundRecordTaskOrder(this, "Second Task"));
});
task_runner_->PostTask(FROM_HERE, BoundRecordTaskOrder(this, "First Task"));
dispatch_async(task_runner_->GetDispatchQueue(), ^{
TaskOrderMarker marker(this, "Second Block");
});
+ task_runner_->PostTask(FROM_HERE, BoundRecordTaskOrder(this, "Second Task"));
DispatchLastTask();
const char* const expectations[] = {
@@ -152,24 +151,22 @@ TEST_F(LibDispatchTaskRunnerTest, FLAKY_DispatchAndPostTasks) {
VerifyTaskOrder(expectations, arraysize(expectations));
}
-// This test is flaky, see http://crbug.com/165118.
-TEST_F(LibDispatchTaskRunnerTest, FLAKY_NonNestable) {
+TEST_F(LibDispatchTaskRunnerTest, NonNestable) {
task_runner_->PostTask(FROM_HERE, base::BindBlock(^{
TaskOrderMarker marker(this, "First");
task_runner_->PostNonNestableTask(FROM_HERE, base::BindBlock(^{
- TaskOrderMarker marker(this, "Third NonNestable");
+ TaskOrderMarker marker(this, "Second NonNestable");
+ (&message_loop_)->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}));
}));
- task_runner_->PostTask(FROM_HERE, BoundRecordTaskOrder(this, "Second"));
- DispatchLastTask();
+ message_loop_.Run();
+ task_runner_->Shutdown();
const char* const expectations[] = {
"BEGIN First",
"END First",
- "BEGIN Second",
- "END Second",
- "BEGIN Third NonNestable",
- "END Third NonNestable"
+ "BEGIN Second NonNestable",
+ "END Second NonNestable"
};
VerifyTaskOrder(expectations, arraysize(expectations));
}
@@ -188,6 +185,7 @@ TEST_F(LibDispatchTaskRunnerTest, PostDelayed) {
}), delta);
task_runner_->PostTask(FROM_HERE, BoundRecordTaskOrder(this, "Second"));
message_loop_.Run();
+ task_runner_->Shutdown();
const char* const expectations[] = {
"BEGIN First",
@@ -201,3 +199,23 @@ TEST_F(LibDispatchTaskRunnerTest, PostDelayed) {
EXPECT_GE(run_time, post_time + delta);
}
+
+TEST_F(LibDispatchTaskRunnerTest, PostAfterShutdown) {
+ EXPECT_TRUE(task_runner_->PostTask(FROM_HERE,
+ BoundRecordTaskOrder(this, "First")));
+ EXPECT_TRUE(task_runner_->PostTask(FROM_HERE,
+ BoundRecordTaskOrder(this, "Second")));
+ task_runner_->Shutdown();
+ EXPECT_FALSE(task_runner_->PostTask(FROM_HERE, base::BindBlock(^{
+ TaskOrderMarker marker(this, "Not Run");
+ ADD_FAILURE() << "Should not run a task after Shutdown";
+ })));
+
+ const char* const expectations[] = {
+ "BEGIN First",
+ "END First",
+ "BEGIN Second",
+ "END Second"
+ };
+ VerifyTaskOrder(expectations, arraysize(expectations));
+}
« no previous file with comments | « base/mac/libdispatch_task_runner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698