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

Side by Side Diff: mojo/edk/system/channel_unittest.cc

Issue 2084593005: Rationalize AddAwakable...() and RemoveAwakable...() methods. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/system/awakable_list_unittest.cc ('k') | mojo/edk/system/core.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "mojo/edk/system/channel_endpoint.h" 9 #include "mojo/edk/system/channel_endpoint.h"
10 #include "mojo/edk/system/channel_endpoint_id.h" 10 #include "mojo/edk/system/channel_endpoint_id.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 io_thread()->PostTaskAndWait([this]() { CreateAndInitChannelOnIOThread(0); }); 57 io_thread()->PostTaskAndWait([this]() { CreateAndInitChannelOnIOThread(0); });
58 58
59 RefPtr<ChannelEndpoint> channel_endpoint; 59 RefPtr<ChannelEndpoint> channel_endpoint;
60 auto mp = MessagePipe::CreateLocalProxy(&channel_endpoint); 60 auto mp = MessagePipe::CreateLocalProxy(&channel_endpoint);
61 61
62 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); 62 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint));
63 63
64 Waiter waiter; 64 Waiter waiter;
65 waiter.Init(); 65 waiter.Init();
66 ASSERT_EQ(MOJO_RESULT_OK, 66 ASSERT_EQ(MOJO_RESULT_OK,
67 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, false, 123, 67 mp->AddAwakable(0, &waiter, 123, false, MOJO_HANDLE_SIGNAL_READABLE,
68 nullptr)); 68 nullptr));
69 69
70 // Don't wait for the shutdown to run ... 70 // Don't wait for the shutdown to run ...
71 io_thread()->PostTaskAndWait([this]() { ShutdownChannelOnIOThread(0); }); 71 io_thread()->PostTaskAndWait([this]() { ShutdownChannelOnIOThread(0); });
72 72
73 // ... since this |Wait()| should fail once the channel is shut down. 73 // ... since this |Wait()| should fail once the channel is shut down.
74 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 74 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
75 waiter.Wait(MOJO_DEADLINE_INDEFINITE, nullptr, nullptr)); 75 waiter.Wait(MOJO_DEADLINE_INDEFINITE, nullptr, nullptr));
76 HandleSignalsState hss; 76 HandleSignalsState hss;
77 mp->RemoveAwakable(0, &waiter, &hss); 77 mp->RemoveAwakable(0, false, &waiter, 0, &hss);
78 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); 78 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals);
79 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); 79 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals);
80 80
81 mp->Close(0); 81 mp->Close(0);
82 82
83 EXPECT_TRUE(channel(0)->HasOneRef()); 83 EXPECT_TRUE(channel(0)->HasOneRef());
84 } 84 }
85 85
86 // ChannelTest.WaitAfterAttachRunAndShutdown ----------------------------------- 86 // ChannelTest.WaitAfterAttachRunAndShutdown -----------------------------------
87 87
88 TEST_F(ChannelTest, WaitAfterAttachRunAndShutdown) { 88 TEST_F(ChannelTest, WaitAfterAttachRunAndShutdown) {
89 io_thread()->PostTaskAndWait([this]() { CreateAndInitChannelOnIOThread(0); }); 89 io_thread()->PostTaskAndWait([this]() { CreateAndInitChannelOnIOThread(0); });
90 90
91 RefPtr<ChannelEndpoint> channel_endpoint; 91 RefPtr<ChannelEndpoint> channel_endpoint;
92 auto mp = MessagePipe::CreateLocalProxy(&channel_endpoint); 92 auto mp = MessagePipe::CreateLocalProxy(&channel_endpoint);
93 93
94 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); 94 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint));
95 95
96 io_thread()->PostTaskAndWait([this]() { ShutdownChannelOnIOThread(0); }); 96 io_thread()->PostTaskAndWait([this]() { ShutdownChannelOnIOThread(0); });
97 97
98 Waiter waiter; 98 Waiter waiter;
99 waiter.Init(); 99 waiter.Init();
100 HandleSignalsState hss; 100 HandleSignalsState hss;
101 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 101 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
102 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, false, 123, 102 mp->AddAwakable(0, &waiter, 123, false, MOJO_HANDLE_SIGNAL_READABLE,
103 &hss)); 103 &hss));
104 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); 104 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals);
105 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); 105 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals);
106 106
107 mp->Close(0); 107 mp->Close(0);
108 108
109 EXPECT_TRUE(channel(0)->HasOneRef()); 109 EXPECT_TRUE(channel(0)->HasOneRef());
110 } 110 }
111 111
112 // ChannelTest.EndpointChannelShutdownRace ------------------------------------- 112 // ChannelTest.EndpointChannelShutdownRace -------------------------------------
(...skipping 19 matching lines...) Expand all
132 io_thread()->PostTaskAndWait([]() {}); 132 io_thread()->PostTaskAndWait([]() {});
133 EXPECT_FALSE(channel(0)); 133 EXPECT_FALSE(channel(0));
134 } 134 }
135 } 135 }
136 136
137 // TODO(vtl): More. ------------------------------------------------------------ 137 // TODO(vtl): More. ------------------------------------------------------------
138 138
139 } // namespace 139 } // namespace
140 } // namespace system 140 } // namespace system
141 } // namespace mojo 141 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/awakable_list_unittest.cc ('k') | mojo/edk/system/core.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698