| 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));
|
| }
|
|
|