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

Side by Side Diff: net/test/local_test_server_posix.cc

Issue 13890022: Use base::TimeTicks instead of base::Time to resolve flaky tests using local_test_server_posix.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/test/local_test_server.h" 5 #include "net/test/local_test_server.h"
6 6
7 #include <poll.h> 7 #include <poll.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 std::string port_string_; 53 std::string port_string_;
54 DISALLOW_COPY_AND_ASSIGN(OrphanedTestServerFilter); 54 DISALLOW_COPY_AND_ASSIGN(OrphanedTestServerFilter);
55 }; 55 };
56 56
57 // Given a file descriptor, reads into |buffer| until |bytes_max| 57 // Given a file descriptor, reads into |buffer| until |bytes_max|
58 // bytes has been read or an error has been encountered. Returns true 58 // bytes has been read or an error has been encountered. Returns true
59 // if the read was successful. |remaining_time| is used as a timeout. 59 // if the read was successful. |remaining_time| is used as a timeout.
60 bool ReadData(int fd, ssize_t bytes_max, uint8* buffer, 60 bool ReadData(int fd, ssize_t bytes_max, uint8* buffer,
61 base::TimeDelta* remaining_time) { 61 base::TimeDelta* remaining_time) {
62 ssize_t bytes_read = 0; 62 ssize_t bytes_read = 0;
63 base::Time previous_time = base::Time::Now(); 63 base::TimeTicks previous_time = base::TimeTicks::Now();
64 while (bytes_read < bytes_max) { 64 while (bytes_read < bytes_max) {
65 struct pollfd poll_fds[1]; 65 struct pollfd poll_fds[1];
66 66
67 poll_fds[0].fd = fd; 67 poll_fds[0].fd = fd;
68 poll_fds[0].events = POLLIN | POLLPRI; 68 poll_fds[0].events = POLLIN | POLLPRI;
69 poll_fds[0].revents = 0; 69 poll_fds[0].revents = 0;
70 70
71 int rv = HANDLE_EINTR(poll(poll_fds, 1, 71 int rv = HANDLE_EINTR(poll(poll_fds, 1,
72 remaining_time->InMilliseconds())); 72 remaining_time->InMilliseconds()));
73 if (rv == 0) { 73 if (rv == 0) {
74 LOG(ERROR) << "poll() timed out; bytes_read=" << bytes_read; 74 LOG(ERROR) << "poll() timed out; bytes_read=" << bytes_read;
75 return false; 75 return false;
76 } else if (rv < 0) { 76 } else if (rv < 0) {
77 PLOG(ERROR) << "poll() failed for child file descriptor; bytes_read=" 77 PLOG(ERROR) << "poll() failed for child file descriptor; bytes_read="
78 << bytes_read; 78 << bytes_read;
79 return false; 79 return false;
80 } 80 }
81 81
82 base::Time current_time = base::Time::Now(); 82 base::TimeTicks current_time = base::TimeTicks::Now();
83 base::TimeDelta elapsed_time_cycle = current_time - previous_time; 83 base::TimeDelta elapsed_time_cycle = current_time - previous_time;
84 DCHECK_GE(elapsed_time_cycle.InMilliseconds(), 0); 84 DCHECK_GE(elapsed_time_cycle.InMilliseconds(), 0);
85 *remaining_time -= elapsed_time_cycle; 85 *remaining_time -= elapsed_time_cycle;
86 previous_time = current_time; 86 previous_time = current_time;
87 87
88 ssize_t num_bytes = HANDLE_EINTR(read(fd, buffer + bytes_read, 88 ssize_t num_bytes = HANDLE_EINTR(read(fd, buffer + bytes_read,
89 bytes_max - bytes_read)); 89 bytes_max - bytes_read));
90 if (num_bytes <= 0) 90 if (num_bytes <= 0)
91 return false; 91 return false;
92 bytes_read += num_bytes; 92 bytes_read += num_bytes;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 if (!ParseServerData(server_data)) { 172 if (!ParseServerData(server_data)) {
173 LOG(ERROR) << "Could not parse server_data: " << server_data; 173 LOG(ERROR) << "Could not parse server_data: " << server_data;
174 return false; 174 return false;
175 } 175 }
176 176
177 return true; 177 return true;
178 } 178 }
179 179
180 } // namespace net 180 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698