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

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

Issue 2096683003: Add yet another threaded test of WaitSetDispatcher. (Closed) Base URL: https://github.com/domokit/mojo.git@work792_wait_set_5.2-x-work791_wait_set_5.1-x-work790_wait_set_5
Patch Set: improve test and fix bug Created 4 years, 6 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/wait_set_dispatcher.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/wait_set_dispatcher_unittest.cc
diff --git a/mojo/edk/system/wait_set_dispatcher_unittest.cc b/mojo/edk/system/wait_set_dispatcher_unittest.cc
index 446ec89df9240bf2096fbb319cdb6409e8e0d039..57d61cfdb9484828f4acaa7d044958c9b4603dd7 100644
--- a/mojo/edk/system/wait_set_dispatcher_unittest.cc
+++ b/mojo/edk/system/wait_set_dispatcher_unittest.cc
@@ -10,6 +10,7 @@
#include "mojo/edk/system/wait_set_dispatcher.h"
#include <thread>
+#include <vector>
#include "mojo/edk/platform/test_stopwatch.h"
#include "mojo/edk/platform/thread_utils.h"
@@ -592,7 +593,52 @@ TEST(WaitSetDispatcherTest, BasicThreaded2) {
EXPECT_EQ(MOJO_RESULT_OK, d->Close());
}
-// TODO(vtl): Test waiting on multiple threads.
+TEST(WaitSetDispatcherTest, BasicThreaded3) {
+ static constexpr auto kNone = MOJO_HANDLE_SIGNAL_NONE;
+ static constexpr auto kR = MOJO_HANDLE_SIGNAL_READABLE;
+
+ const auto epsilon = test::EpsilonTimeout();
+
+ Stopwatch stopwatch;
+
+ auto d = WaitSetDispatcher::Create(WaitSetDispatcher::kDefaultCreateOptions);
+ auto d_member = MakeRefCounted<test::MockSimpleDispatcher>(kNone, kR);
+
+ {
+ // Add an entry.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ d->WaitSetAdd(NullUserPointer(), d_member.Clone(), kR, 123u));
+
+ // Wait on a bunch of threads. We'll trigger on the main thread.
+ std::vector<std::thread> threads;
+ for (size_t i = 0; i < 4; i++) {
+ threads.push_back(std::thread([epsilon, d, d_member]() {
+ uint32_t num_results = 10u;
+ MojoWaitSetResult results[10] = {};
+ EXPECT_EQ(MOJO_RESULT_OK,
+ d->WaitSetWait(5 * epsilon, MakeUserPointer(&num_results),
+ MakeUserPointer(results), NullUserPointer()));
+ EXPECT_EQ(1u, num_results);
+ EXPECT_TRUE(CheckHasResult(num_results, results, 123u, kR,
+ MOJO_RESULT_OK,
+ d_member->GetHandleSignalsState()));
+ }));
+ }
+
+ // Sleep a bit, to try to ensure that all the threads are already waiting.
+ ThreadSleep(epsilon);
+
+ // Trigger the entry.
+ d_member->SetSatisfiedSignals(kR);
+
+ for (auto& t : threads)
+ t.join();
+ }
+
+ EXPECT_EQ(MOJO_RESULT_OK, d_member->Close());
+ EXPECT_EQ(MOJO_RESULT_OK, d->Close());
+}
+
// TODO(vtl): Stress tests.
// TODO(vtl): Test options validation for "create" and "add" (not that there's
« no previous file with comments | « mojo/edk/system/wait_set_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698