Sleep for longer when waiting for test_http_server to start

Due to apparently very overloaded buildbots that runs unittests with a
very low-priority nice level, we can apparently be delayed many
minutes (even 20!). When launching the test_http_server, use
exponential backoff, never going beyond 60 minutes. With the given
values, we'll not go beyond ~32 minutes.

BUG=chromium-os:19391
TEST=ran tests on x86 and amd64

Change-Id: I961d60a6a2fb3d96f405edfd4a72b1cabf46b03a
Reviewed-on: http://gerrit.chromium.org/gerrit/6320
Tested-by: Andrew de los Reyes <adlr@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
diff --git a/http_fetcher_unittest.cc b/http_fetcher_unittest.cc
index a6c3f73..5377cd3 100644
--- a/http_fetcher_unittest.cc
+++ b/http_fetcher_unittest.cc
@@ -102,16 +102,20 @@
       return;
     }
     int rc = 1;
-    int tries = 10;
+    const uint64_t kMaxSleep = 60UL * 60UL * 1000UL * 1000UL;  // 60 min
+    uint64_t timeout = 15 * 1000;  // 15 ms
     started_ = true;
     while (0 != rc) {
       LOG(INFO) << "running wget to start";
       rc = system((string("wget --output-document=/dev/null ") +
                    LocalServerUrlForPath("/test")).c_str());
       LOG(INFO) << "done running wget to start";
-      usleep(10 * 1000);  // 10 ms
-      tries--;
-      if (tries == 0) {
+      if (timeout < (1000 * 1000))  // sub 1-second sleep, use usleep
+        usleep(static_cast<useconds_t>(timeout));
+      else
+        sleep(static_cast<unsigned int>(timeout / (1000 * 1000)));
+      timeout *= 2;
+      if (timeout > kMaxSleep) {
         LOG(ERROR) << "Unable to start server.";
         started_ = false;
         break;