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

Side by Side Diff: remoting/test/chromoting_test_driver_environment.cc

Issue 2734543002: Adding 'Show Host List' option to CTD (Closed)
Patch Set: Clean up Created 3 years, 9 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
« no previous file with comments | « remoting/test/chromoting_test_driver_environment.h ('k') | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "remoting/test/chromoting_test_driver_environment.h" 5 #include "remoting/test/chromoting_test_driver_environment.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 if (!RetrieveAccessToken(auth_code)) { 79 if (!RetrieveAccessToken(auth_code)) {
80 // If we cannot retrieve an access token, then nothing is going to work. 80 // If we cannot retrieve an access token, then nothing is going to work.
81 // Let the caller know that our object is not ready to be used. 81 // Let the caller know that our object is not ready to be used.
82 return false; 82 return false;
83 } 83 }
84 84
85 return true; 85 return true;
86 } 86 }
87 87
88 void ChromotingTestDriverEnvironment::DisplayHostList() { 88 void ChromotingTestDriverEnvironment::DisplayHostList() {
89 const char kHostAvailabilityFormatString[] = "%-45s%-15s%-35s"; 89 const char kHostAvailabilityFormatString[] = "%-25s%-15s%-35s\n";
90 90
91 LOG(INFO) << base::StringPrintf(kHostAvailabilityFormatString, 91 printf(kHostAvailabilityFormatString, "Host Name", "Host Status", "Host JID");
garykac 2017/03/03 21:01:58 Is the switch to printf intentional?
joedow 2017/03/03 22:45:59 It was intentional. Using LOG will prepend a bunc
92 "Host Name", "Host Status", "Host JID"); 92 printf(kHostAvailabilityFormatString, "---------", "-----------", "--------");
93 LOG(INFO) << base::StringPrintf(kHostAvailabilityFormatString,
94 "---------", "-----------", "--------");
95 93
96 std::string status; 94 std::string status;
97 for (const HostInfo& host_info : host_list_) { 95 for (const HostInfo& host_info : host_list_) {
98 HostStatus host_status = host_info.status; 96 HostStatus host_status = host_info.status;
99 if (host_status == kHostStatusOnline) { 97 if (host_status == kHostStatusOnline) {
100 status = "ONLINE"; 98 status = "ONLINE";
101 } else if (host_status == kHostStatusOffline) { 99 } else if (host_status == kHostStatusOffline) {
102 status = "OFFLINE"; 100 status = "OFFLINE";
103 } else { 101 } else {
104 status = "UNKNOWN"; 102 status = "UNKNOWN";
105 } 103 }
106 104
107 LOG(INFO) << base::StringPrintf( 105 printf(kHostAvailabilityFormatString, host_info.host_name.c_str(),
108 kHostAvailabilityFormatString, host_info.host_name.c_str(), 106 status.c_str(), host_info.host_jid.c_str());
109 status.c_str(), host_info.host_jid.c_str());
110 } 107 }
111 } 108 }
112 109
113 bool ChromotingTestDriverEnvironment::WaitForHostOnline( 110 bool ChromotingTestDriverEnvironment::WaitForHostOnline() {
114 const std::string& host_jid,
115 const std::string& host_name) {
116 if (host_list_.empty()) { 111 if (host_list_.empty()) {
117 RetrieveHostList(); 112 RetrieveHostList();
118 } 113 }
119 114
115 DisplayHostList();
116
120 // Refresh the |host_list_| periodically to check if expected JID is online. 117 // Refresh the |host_list_| periodically to check if expected JID is online.
121 const base::TimeDelta kTotalTimeInSeconds = base::TimeDelta::FromSeconds(60); 118 const base::TimeDelta kTotalTimeInSeconds = base::TimeDelta::FromSeconds(60);
122 const base::TimeDelta kSleepTimeInSeconds = base::TimeDelta::FromSeconds(5); 119 const base::TimeDelta kSleepTimeInSeconds = base::TimeDelta::FromSeconds(5);
123 const int kMaxIterations = kTotalTimeInSeconds / kSleepTimeInSeconds; 120 const int kMaxIterations = kTotalTimeInSeconds / kSleepTimeInSeconds;
124 121
125 int num_iterations = 0; 122 int num_iterations = 0;
garykac 2017/03/03 21:01:58 No longer used.
joedow 2017/03/03 22:45:59 Good catch
126 while (num_iterations < kMaxIterations) { 123 for (int iterations = 0; iterations < kMaxIterations; iterations++) {
124 if (!FindHostInHostList()) {
125 LOG(WARNING) << "Host '" << host_name_ << "' with JID '" << host_jid_
126 << "' not found in host list.";
127 return false;
128 }
129
127 if (host_info_.IsReadyForConnection()) { 130 if (host_info_.IsReadyForConnection()) {
128 if (num_iterations > 0) { 131 if (iterations > 0) {
129 VLOG(0) << "Host online after: " 132 VLOG(0) << "Host online after: "
130 << num_iterations * kSleepTimeInSeconds.InSeconds() 133 << iterations * kSleepTimeInSeconds.InSeconds() << " seconds.";
131 << " seconds.";
132 } 134 }
133 return true; 135 return true;
134 } 136 }
135 137
136 // Wait a while before refreshing host list. 138 // Wait a while before refreshing host list.
137 base::PlatformThread::Sleep(kSleepTimeInSeconds); 139 base::PlatformThread::Sleep(kSleepTimeInSeconds);
138 RefreshHostList(); 140 RefreshHostList();
139 ++num_iterations;
140 } 141 }
141 142
142 LOG(ERROR) << "Host with JID '" << host_jid << "' still not online after " 143 LOG(ERROR) << "Host '" << host_name_ << "' with JID '" << host_jid_
144 << "' still not online after "
143 << num_iterations * kSleepTimeInSeconds.InSeconds() << " seconds."; 145 << num_iterations * kSleepTimeInSeconds.InSeconds() << " seconds.";
144 return false; 146 return false;
145 } 147 }
146 148
149 bool ChromotingTestDriverEnvironment::FindHostInHostList() {
150 bool host_found = false;
151 for (HostInfo& host_info : host_list_) {
152 // The JID is optional so we consider an empty string to be a '*' match.
153 bool host_jid_match =
154 host_jid_.empty() || (host_jid_ == host_info.host_jid);
155 bool host_name_match = host_name_ == host_info.host_name;
156
157 if (host_name_match && host_jid_match) {
158 host_info_ = host_info;
159 host_found = true;
160 break;
161 }
162 }
163 return host_found;
164 }
165
147 void ChromotingTestDriverEnvironment::SetAccessTokenFetcherForTest( 166 void ChromotingTestDriverEnvironment::SetAccessTokenFetcherForTest(
148 AccessTokenFetcher* access_token_fetcher) { 167 AccessTokenFetcher* access_token_fetcher) {
149 DCHECK(access_token_fetcher); 168 DCHECK(access_token_fetcher);
150 169
151 test_access_token_fetcher_ = access_token_fetcher; 170 test_access_token_fetcher_ = access_token_fetcher;
152 } 171 }
153 172
154 void ChromotingTestDriverEnvironment::SetRefreshTokenStoreForTest( 173 void ChromotingTestDriverEnvironment::SetRefreshTokenStoreForTest(
155 RefreshTokenStore* refresh_token_store) { 174 RefreshTokenStore* refresh_token_store) {
156 DCHECK(refresh_token_store); 175 DCHECK(refresh_token_store);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 318
300 run_loop.Run(); 319 run_loop.Run();
301 320
302 if (host_list_.empty()) { 321 if (host_list_.empty()) {
303 // Note: Access token may have expired, but it is unlikely. 322 // Note: Access token may have expired, but it is unlikely.
304 LOG(ERROR) << "Retrieved host list is empty.\n" 323 LOG(ERROR) << "Retrieved host list is empty.\n"
305 << "Does the account have hosts set up?"; 324 << "Does the account have hosts set up?";
306 return false; 325 return false;
307 } 326 }
308 327
309 DisplayHostList(); 328 return true;
310 for (HostInfo& host_info : host_list_) {
311 // The JID is optional so we consider an empty string to be a '*' match.
312 bool host_jid_match =
313 host_jid_.empty() || (host_jid_ == host_info.host_jid);
314 bool host_name_match = host_name_ == host_info.host_name;
315
316 if (host_name_match && host_jid_match) {
317 host_info_ = host_info;
318
319 if (host_info.IsReadyForConnection()) {
320 return true;
321 } else {
322 LOG(WARNING) << "Host '" << host_name_ << "' with JID '" << host_jid_
323 << "' not online.";
324 return false;
325 }
326 }
327 }
328 LOG(WARNING) << "Host '" << host_name_ << "' with JID '" << host_jid_
329 << "' not found in host list.";
330 return false;
331 } 329 }
332 330
333 void ChromotingTestDriverEnvironment::OnHostListRetrieved( 331 void ChromotingTestDriverEnvironment::OnHostListRetrieved(
334 base::Closure done_closure, 332 base::Closure done_closure,
335 const std::vector<HostInfo>& retrieved_host_list) { 333 const std::vector<HostInfo>& retrieved_host_list) {
336 VLOG(1) << "OnHostListRetrieved() Called"; 334 VLOG(1) << "OnHostListRetrieved() Called";
337 335
338 host_list_ = retrieved_host_list; 336 host_list_ = retrieved_host_list;
339 337
340 done_closure.Run(); 338 done_closure.Run();
341 } 339 }
342 340
343 } // namespace test 341 } // namespace test
344 } // namespace remoting 342 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/chromoting_test_driver_environment.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698