Confirm artifact existing before downloading in a new thread.

Call method WaitForArtifactToExist to make sure all artifact exist before
starting downloading in a new thread. This prevents caller from waiting
indefinitely for any nonexistent artifact.

BUG=chromium:270819
TEST=test with run_suite in a local setup of devserver

Change-Id: I0b2af27e0abe5fd7ede63c492e4e2f4f8be0c56e
Reviewed-on: https://gerrit.chromium.org/gerrit/65397
Reviewed-by: Dan Shi <dshi@chromium.org>
Tested-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/downloader.py b/downloader.py
index e4734a2..e8e67f0 100755
--- a/downloader.py
+++ b/downloader.py
@@ -124,8 +124,14 @@
     required_artifacts = factory.RequiredArtifacts()
     str_repr = [str(a) for a in required_artifacts]
     self._Log('Downloading artifacts %s.', ' '.join(str_repr))
+
     try:
       if async:
+        # Make sure all artifacts exist before starting downloading in a new
+        # thread. This prevents caller from waiting indefinitely for any
+        # nonexistent artifact.
+        for artifact in required_artifacts:
+          artifact.WaitForArtifactToExist(timeout=10)
         self._DownloadArtifactsInBackground(required_artifacts)
       else:
         self._DownloadArtifactsSerially(required_artifacts, no_wait=True)