Index: webrtc/base/socket_unittest.cc |
diff --git a/webrtc/base/socket_unittest.cc b/webrtc/base/socket_unittest.cc |
index 0b282cd66053bbfa723517a19b3a75ff31c208a4..8aaa2bb827b156a60971c5fcf3404fd01acf3cc4 100644 |
--- a/webrtc/base/socket_unittest.cc |
+++ b/webrtc/base/socket_unittest.cc |
@@ -184,10 +184,15 @@ void SocketTest::TestGetSetOptionsIPv6() { |
GetSetOptionsInternal(kIPv6Loopback); |
} |
-void SocketTest::TestSocketRecvTimestamp() { |
+void SocketTest::TestSocketRecvTimestampIPv4() { |
SocketRecvTimestamp(kIPv4Loopback); |
} |
+void SocketTest::TestSocketRecvTimestampIPv6() { |
+ MAYBE_SKIP_IPV6; |
+ SocketRecvTimestamp(kIPv6Loopback); |
+} |
+ |
// For unbound sockets, GetLocalAddress / GetRemoteAddress return AF_UNSPEC |
// values on Windows, but an empty address of the same family on Linux/MacOS X. |
bool IsUnspecOrEmptyIP(const IPAddress& address) { |
@@ -1033,19 +1038,26 @@ void SocketTest::SocketRecvTimestamp(const IPAddress& loopback) { |
EXPECT_EQ(0, socket->Bind(SocketAddress(loopback, 0))); |
SocketAddress address = socket->GetLocalAddress(); |
+ uint64_t send_time_1 = TimeMicros(); |
socket->SendTo("foo", 3, address); |
- int64_t timestamp; |
+ int64_t recv_timestamp_1; |
char buffer[3]; |
- socket->RecvFrom(buffer, 3, nullptr, ×tamp); |
- EXPECT_GT(timestamp, -1); |
- int64_t prev_timestamp = timestamp; |
+ socket->RecvFrom(buffer, 3, nullptr, &recv_timestamp_1); |
+ EXPECT_GT(recv_timestamp_1, -1); |
- const int64_t kTimeBetweenPacketsMs = 10; |
+ const int64_t kTimeBetweenPacketsMs = 100; |
Thread::SleepMs(kTimeBetweenPacketsMs); |
+ uint64_t send_time_2 = TimeMicros(); |
socket->SendTo("bar", 3, address); |
- socket->RecvFrom(buffer, 3, nullptr, ×tamp); |
- EXPECT_NEAR(timestamp, prev_timestamp + kTimeBetweenPacketsMs * 1000, 2000); |
+ int64_t recv_timestamp_2; |
+ socket->RecvFrom(buffer, 3, nullptr, &recv_timestamp_2); |
+ |
+ int64_t system_time_diff = send_time_2 - send_time_1; |
+ int64_t recv_timestamp_diff = recv_timestamp_2 - recv_timestamp_1; |
+ // Compare against the system time at the point of sending, because |
+ // SleepMs may not sleep for exactly the requested time. |
+ EXPECT_NEAR(system_time_diff, recv_timestamp_diff, 10000); |
} |
} // namespace rtc |