From a8b8e13154fe39396b9139e8409cb822bbe0a68a Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Fri, 25 Jan 2019 22:37:41 -0800 Subject: Deflake socket_stream_blocking tests. PiperOrigin-RevId: 231020482 Change-Id: Idd9168678b18d03aac473adcc40902e27e06d0a1 --- test/syscalls/linux/socket_stream_blocking.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/syscalls/linux/socket_stream_blocking.cc b/test/syscalls/linux/socket_stream_blocking.cc index a04f2d7d0..8b3f6a647 100644 --- a/test/syscalls/linux/socket_stream_blocking.cc +++ b/test/syscalls/linux/socket_stream_blocking.cc @@ -62,12 +62,14 @@ TEST_P(BlockingStreamSocketPairTest, BlockPartialWriteClosed) { }); // Leave time for write to become blocked. - absl::SleepFor(absl::Seconds(1.0)); + absl::SleepFor(absl::Seconds(1)); ASSERT_THAT(close(sockets->release_second_fd()), SyscallSucceeds()); } -TEST_P(BlockingStreamSocketPairTest, SendMsgTooLarge) { +// Random save may interrupt the call to sendmsg() in SendLargeSendMsg(), +// causing the write to be incomplete and the test to hang. +TEST_P(BlockingStreamSocketPairTest, SendMsgTooLarge_NoRandomSave) { auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); int sndbuf; @@ -142,11 +144,15 @@ TEST_P(BlockingStreamSocketPairTest, SendTimeout) { setsockopt(sockets->first_fd(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)), SyscallSucceeds()); - char buf[100] = {}; + std::vector buf(kPageSize); + // We don't know how much data the socketpair will buffer, so we may do an + // arbitrarily large number of writes; saving after each write causes this + // test's time to explode. + const DisableSave ds; for (;;) { int ret; ASSERT_THAT( - ret = RetryEINTR(send)(sockets->first_fd(), buf, sizeof(buf), 0), + ret = RetryEINTR(send)(sockets->first_fd(), buf.data(), buf.size(), 0), ::testing::AnyOf(SyscallSucceeds(), SyscallFailsWithErrno(EAGAIN))); if (ret == -1) { break; -- cgit v1.2.3