Tweak http_fetcher_unittest.cc error handling

- make sure success on last time through loop isn't seen as failure
- avoid extra sleep after success
- avoid extra sleep after final failure

BUG=chromium-os:19391
TEST=Run unittests to ensure no breakage

Change-Id: I3f0f999effede21a6948dde8aa4f3920403b0205
Reviewed-on: http://gerrit.chromium.org/gerrit/6415
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
Tested-by: Josh Horwich <jhorwich@google.com>
diff --git a/http_fetcher_unittest.cc b/http_fetcher_unittest.cc
index 5377cd3..66552ff 100644
--- a/http_fetcher_unittest.cc
+++ b/http_fetcher_unittest.cc
@@ -110,15 +110,17 @@
       rc = system((string("wget --output-document=/dev/null ") +
                    LocalServerUrlForPath("/test")).c_str());
       LOG(INFO) << "done running wget to start";
-      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;
+      if (0 != rc) {
+        if (timeout > kMaxSleep) {
+          LOG(ERROR) << "Unable to start server.";
+          started_ = false;
+          break;
+        }
+        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;
       }
     }
     free(argv[0]);