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

Unified Diff: mojo/shell/data_pipe_peek_unittest.cc

Issue 1552983003: Fix a bunch of mojo_public_*_unittests with the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 12 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/shell/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/data_pipe_peek_unittest.cc
diff --git a/mojo/shell/data_pipe_peek_unittest.cc b/mojo/shell/data_pipe_peek_unittest.cc
index 139008efb01cb43692cfa4b46e4a6092371f702d..3e5ff1b07f0ee6e4f4cbe342531f961c8250419c 100644
--- a/mojo/shell/data_pipe_peek_unittest.cc
+++ b/mojo/shell/data_pipe_peek_unittest.cc
@@ -6,12 +6,19 @@
#include <stddef.h>
#include <stdint.h>
-
+
+#include "mojo/edk/system/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace runner {
namespace {
+
+// In various places, we have to poll (since, e.g., we can't yet wait for a
+// certain amount of data to be available). This is the maximum number of
+// iterations (separated by a short sleep).
+// TODO(vtl): Get rid of this.
+const size_t kMaxPoll = 100;
TEST(DataPipePeek, PeekNBytes) {
DataPipe data_pipe;
@@ -29,7 +36,7 @@ TEST(DataPipePeek, PeekNBytes) {
// We're not consuming data, so peeking for 4 bytes should always succeed.
std::string bytes;
- MojoDeadline timeout = 0;
+ MojoDeadline timeout = MOJO_DEADLINE_INDEFINITE;
EXPECT_TRUE(shell::BlockingPeekNBytes(consumer, &bytes, num_bytes4, timeout));
EXPECT_EQ(bytes, std::string(s4));
@@ -96,17 +103,27 @@ TEST(DataPipePeek, PeekLine) {
uint32_t bytes1 = 1;
const char* s1 = "\n";
+ timeout = MOJO_DEADLINE_INDEFINITE;
EXPECT_EQ(MOJO_RESULT_OK,
WriteDataRaw(producer, s1, &bytes1, MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(1u, bytes1);
- EXPECT_TRUE(shell::BlockingPeekLine(consumer, &str, max_str_length, timeout));
+ bool succeeded = false;
+ for (size_t i = 0; i < kMaxPoll; i++) {
+ if (shell::BlockingPeekLine(consumer, &str, max_str_length, timeout)) {
+ succeeded = true;
+ break;
+ }
+ edk::test::Sleep(edk::test::EpsilonDeadline());
+ }
+ EXPECT_TRUE(succeeded);
EXPECT_EQ(str, std::string(s4) + "\n");
// If the max_line_length parameter is less than the length of the
// newline terminated string, then peek should fail.
max_str_length = 3;
+ timeout = 0;
EXPECT_FALSE(
shell::BlockingPeekLine(consumer, &str, max_str_length, timeout));
}
« no previous file with comments | « mojo/shell/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698