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

Unified Diff: mojo/edk/system/watch_unittest.cc

Issue 2153733002: [mojo-edk] Prevent AcceptIncomingMessages flushing aggressively (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: -_- Created 4 years, 5 months 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 | « mojo/edk/system/node_controller.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/watch_unittest.cc
diff --git a/mojo/edk/system/watch_unittest.cc b/mojo/edk/system/watch_unittest.cc
index 7b3137f97c411d01d91f0f412b3a97d2ed33d2fc..ec28d94f8058f25d40abcb88bcebbc1161364bed 100644
--- a/mojo/edk/system/watch_unittest.cc
+++ b/mojo/edk/system/watch_unittest.cc
@@ -5,8 +5,11 @@
#include <functional>
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "mojo/edk/system/request_context.h"
#include "mojo/edk/test/mojo_test_base.h"
#include "mojo/public/c/system/functions.h"
@@ -29,7 +32,7 @@ class WatchHelper {
using Callback =
std::function<void(MojoResult result, MojoHandleSignalsState state)>;
- WatchHelper() {}
+ WatchHelper() : task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
~WatchHelper() {
CHECK(!watching_);
}
@@ -55,27 +58,32 @@ class WatchHelper {
watching_ = false;
}
- void ExpectSystemNotifications() { expect_system_notifications_ = true; }
-
private:
static void OnNotify(uintptr_t context,
MojoResult result,
MojoHandleSignalsState state,
MojoWatchNotificationFlags flags) {
WatchHelper* watcher = reinterpret_cast<WatchHelper*>(context);
+ watcher->task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&NotifyOnMainThread, context, result, state, flags));
+ }
+
+ static void NotifyOnMainThread(uintptr_t context,
+ MojoResult result,
+ MojoHandleSignalsState state,
+ MojoWatchNotificationFlags flags) {
+ WatchHelper* watcher = reinterpret_cast<WatchHelper*>(context);
CHECK(watcher->watching_);
if (result == MOJO_RESULT_CANCELLED)
watcher->watching_ = false;
- CHECK_EQ(flags, watcher->expect_system_notifications_?
- MOJO_WATCH_NOTIFICATION_FLAG_FROM_SYSTEM :
- MOJO_WATCH_NOTIFICATION_FLAG_NONE);
watcher->callback_(result, state);
}
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
bool watching_ = false;
MojoHandle handle_;
Callback callback_;
- bool expect_system_notifications_ = false;
DISALLOW_COPY_AND_ASSIGN(WatchHelper);
};
@@ -249,6 +257,7 @@ TEST_F(WatchTest, WatchWhileSatisfied) {
WriteMessage(a, "hey");
bool signaled = false;
WatchHelper b_watcher;
+ base::RunLoop loop;
b_watcher.Watch(
b, MOJO_HANDLE_SIGNAL_READABLE,
[&] (MojoResult result, MojoHandleSignalsState state) {
@@ -256,7 +265,9 @@ TEST_F(WatchTest, WatchWhileSatisfied) {
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE,
state.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE);
signaled = true;
+ loop.Quit();
});
+ loop.Run();
EXPECT_TRUE(signaled);
b_watcher.Cancel();
@@ -419,6 +430,7 @@ TEST_F(WatchTest, NestedCancellation) {
CreateMessagePipe(&a, &b);
CreateMessagePipe(&c, &d);
+ base::RunLoop loop;
bool a_watcher_run = false;
WatchHelper a_watcher;
a_watcher.Watch(
@@ -438,8 +450,9 @@ TEST_F(WatchTest, NestedCancellation) {
// ...but this should prevent that notification from dispatching because
// |a_watcher| is now cancelled.
a_watcher.Cancel();
+
+ loop.Quit();
});
- c_watcher.ExpectSystemNotifications();
{
// Force "system" notifications for the synchronous behavior required to
@@ -451,6 +464,8 @@ TEST_F(WatchTest, NestedCancellation) {
CloseHandle(d);
}
+ loop.Run();
+
EXPECT_FALSE(a_watcher.is_watching());
EXPECT_FALSE(a_watcher_run);
« no previous file with comments | « mojo/edk/system/node_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698