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

Side by Side Diff: http_fetcher_unittest.cc

Issue 2805027: AU: Changes for deltas on traditional bios machines. (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: fixes for review and merging in petkov's recent changes Created 10 years, 5 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 | « delta_performer_unittest.cc ('k') | libcurl_http_fetcher.h » ('j') | 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) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium OS 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 <unistd.h> 5 #include <unistd.h>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 #include <base/scoped_ptr.h> 8 #include <base/scoped_ptr.h>
9 #include <glib.h> 9 #include <glib.h>
10 #include <gtest/gtest.h> 10 #include <gtest/gtest.h>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 argv, 75 argv,
76 NULL, 76 NULL,
77 G_SPAWN_DO_NOT_REAP_CHILD, 77 G_SPAWN_DO_NOT_REAP_CHILD,
78 NULL, 78 NULL,
79 NULL, 79 NULL,
80 &pid_, 80 &pid_,
81 &err)) { 81 &err)) {
82 return; 82 return;
83 } 83 }
84 int rc = 1; 84 int rc = 1;
85 int tries = 10;
86 started_ = true;
85 while (0 != rc) { 87 while (0 != rc) {
88 LOG(INFO) << "running wget to start";
86 rc = system((string("wget --output-document=/dev/null ") + 89 rc = system((string("wget --output-document=/dev/null ") +
87 LocalServerUrlForPath("/test")).c_str()); 90 LocalServerUrlForPath("/test")).c_str());
91 LOG(INFO) << "done running wget to start";
88 usleep(10 * 1000); // 10 ms 92 usleep(10 * 1000); // 10 ms
93 tries--;
94 if (tries == 0) {
95 LOG(ERROR) << "Unable to start server.";
96 started_ = false;
97 break;
98 }
89 } 99 }
90 started_ = true;
91 free(argv[0]); 100 free(argv[0]);
92 return; 101 return;
93 } 102 }
94 ~PythonHttpServer() { 103 ~PythonHttpServer() {
95 if (!started_) 104 if (!started_)
96 return; 105 return;
97 // request that the server exit itself 106 // request that the server exit itself
107 LOG(INFO) << "running wget to exit";
98 int rc = system((string("wget -t 1 --output-document=/dev/null ") + 108 int rc = system((string("wget -t 1 --output-document=/dev/null ") +
99 LocalServerUrlForPath("/quitquitquit")).c_str()); 109 LocalServerUrlForPath("/quitquitquit")).c_str());
110 LOG(INFO) << "done running wget to exit";
100 if (validate_quit_) 111 if (validate_quit_)
101 EXPECT_EQ(0, rc); 112 EXPECT_EQ(0, rc);
102 waitpid(pid_, NULL, 0); 113 waitpid(pid_, NULL, 0);
103 } 114 }
104 GPid pid_; 115 GPid pid_;
105 bool started_; 116 bool started_;
106 bool validate_quit_; 117 bool validate_quit_;
107 }; 118 };
108 119
109 template <> 120 template <>
110 class HttpFetcherTest<LibcurlHttpFetcher> : public ::testing::Test { 121 class HttpFetcherTest<LibcurlHttpFetcher> : public ::testing::Test {
111 public: 122 public:
112 HttpFetcher* NewLargeFetcher() { 123 HttpFetcher* NewLargeFetcher() {
113 LibcurlHttpFetcher *ret = new LibcurlHttpFetcher; 124 LibcurlHttpFetcher *ret = new LibcurlHttpFetcher;
114 ret->set_idle_ms(1); // speeds up test execution 125 ret->set_idle_ms(1000); // speeds up test execution
115 return ret; 126 return ret;
116 } 127 }
117 HttpFetcher* NewSmallFetcher() { 128 HttpFetcher* NewSmallFetcher() {
118 return NewLargeFetcher(); 129 return NewLargeFetcher();
119 } 130 }
120 string BigUrl() const { 131 string BigUrl() const {
121 return LocalServerUrlForPath("/big"); 132 return LocalServerUrlForPath("/big");
122 } 133 }
123 string SmallUrl() const { 134 string SmallUrl() const {
124 return LocalServerUrlForPath("/foo"); 135 return LocalServerUrlForPath("/foo");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 ASSERT_TRUE(server.started_); 185 ASSERT_TRUE(server.started_);
175 186
176 StartTransferArgs start_xfer_args = {fetcher.get(), this->SmallUrl()}; 187 StartTransferArgs start_xfer_args = {fetcher.get(), this->SmallUrl()};
177 188
178 g_timeout_add(0, StartTransfer, &start_xfer_args); 189 g_timeout_add(0, StartTransfer, &start_xfer_args);
179 g_main_loop_run(loop); 190 g_main_loop_run(loop);
180 } 191 }
181 g_main_loop_unref(loop); 192 g_main_loop_unref(loop);
182 } 193 }
183 194
195 TYPED_TEST(HttpFetcherTest, SimpleBigTest) {
196 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
197 {
198 HttpFetcherTestDelegate delegate;
199 delegate.loop_ = loop;
200 scoped_ptr<HttpFetcher> fetcher(this->NewLargeFetcher());
201 fetcher->set_delegate(&delegate);
202
203 typename TestFixture::HttpServer server;
204 ASSERT_TRUE(server.started_);
205
206 StartTransferArgs start_xfer_args = {fetcher.get(), this->BigUrl()};
207
208 g_timeout_add(0, StartTransfer, &start_xfer_args);
209 g_main_loop_run(loop);
210 }
211 g_main_loop_unref(loop);
212 }
213
184 namespace { 214 namespace {
185 class PausingHttpFetcherTestDelegate : public HttpFetcherDelegate { 215 class PausingHttpFetcherTestDelegate : public HttpFetcherDelegate {
186 public: 216 public:
187 virtual void ReceivedBytes(HttpFetcher* fetcher, 217 virtual void ReceivedBytes(HttpFetcher* fetcher,
188 const char* bytes, int length) { 218 const char* bytes, int length) {
189 char str[length + 1]; 219 char str[length + 1];
190 memset(str, 0, length + 1); 220 memset(str, 0, length + 1);
191 memcpy(str, bytes, length); 221 memcpy(str, bytes, length);
192 CHECK(!paused_); 222 CHECK(!paused_);
193 paused_ = true; 223 paused_ = true;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 ASSERT_EQ(100000, delegate.data.size()); 371 ASSERT_EQ(100000, delegate.data.size());
342 for (int i = 0; i < 100000; i += 10) { 372 for (int i = 0; i < 100000; i += 10) {
343 // Assert so that we don't flood the screen w/ EXPECT errors on failure. 373 // Assert so that we don't flood the screen w/ EXPECT errors on failure.
344 ASSERT_EQ(delegate.data.substr(i, 10), "abcdefghij"); 374 ASSERT_EQ(delegate.data.substr(i, 10), "abcdefghij");
345 } 375 }
346 } 376 }
347 g_main_loop_unref(loop); 377 g_main_loop_unref(loop);
348 } 378 }
349 379
350 } // namespace chromeos_update_engine 380 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « delta_performer_unittest.cc ('k') | libcurl_http_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698