Fix two unittests by testing the queue mechanism rather than verifying mocks.
As we can't follow mocks across processes, I'm modifying the downloader_unittests
that tests background to only test the output of the queues rather than checking
of Download/Staging are called in the background process. As that componenet
is already tested in the testDownloaderSerially test, we only need to test
that the background process is communicating correctly back to the main process
by placing Success in the Queues.
BUG=chromium-os:29936
TEST=Ran them.
Change-Id: I893a3712f16e994f12d7e15b409dc65b35cdc821
Reviewed-on: https://gerrit.chromium.org/gerrit/26485
Tested-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Ready: Chris Sosa <sosa@chromium.org>
diff --git a/downloader_unittest.py b/downloader_unittest.py
index b9a1c85..a7ce2b8 100755
--- a/downloader_unittest.py
+++ b/downloader_unittest.py
@@ -39,12 +39,14 @@
if os.path.exists(self._work_dir):
shutil.rmtree(self._work_dir)
- def _CommonDownloaderSetup(self):
+ def _CommonDownloaderSetup(self, ignore_background=False):
"""Common code to downloader tests.
Mocks out key devserver_util module methods, creates mock artifacts
and sets appropriate expectations.
+ @ignore_background Indicate that background artifacts should be ignored.
+
@return iterable of artifact objects with appropriate expectations.
"""
board = 'x86-mario-release'
@@ -59,7 +61,7 @@
).AndReturn(self._work_dir)
tempfile.mkdtemp(suffix=mox.IgnoreArg()).AndReturn(self._work_dir)
- return self._GenerateArtifacts()
+ return self._GenerateArtifacts(ignore_background)
def _CreateArtifactDownloader(self, artifacts):
"""Create and return a Downloader of the appropriate type.
@@ -79,9 +81,12 @@
"""
raise NotImplementedError()
- def _GenerateArtifacts(self):
+ def _GenerateArtifacts(self, ignore_background):
"""Instantiate artifact mocks and set expectations on them.
+ @ignore_background Indicate that background artifacts should be ignored.
+ This gets passed by CommonDownloaderSetup.
+
@return iterable of artifact objects with appropriate expectations.
"""
raise NotImplementedError()
@@ -104,12 +109,14 @@
def _ClassUnderTest(self):
return downloader.Downloader
- def _GenerateArtifacts(self):
+ def _GenerateArtifacts(self, ignore_background):
"""Instantiate artifact mocks and set expectations on them.
Sets up artifacts and sets up expectations for synchronous artifacts to
be downloaded first.
+ @ignore_background If True, doesn't use mocks for download/stage methods.
+
@return iterable of artifact objects with appropriate expectations.
"""
artifacts = []
@@ -122,6 +129,9 @@
artifact.Stage()
else:
artifact.Synchronous = lambda: False
+ if ignore_background:
+ artifact.Download = lambda: None
+ artifact.Stage = lambda: None
artifacts.append(artifact)
@@ -145,14 +155,7 @@
def testDownloaderInBackground(self):
"""Runs through the standard downloader workflow with backgrounding."""
- artifacts = self._CommonDownloaderSetup()
-
- # Downloads non-synchronous artifacts second.
- for index, artifact in enumerate(artifacts):
- if index % 2 != 0:
- artifact.Download()
- artifact.Stage()
-
+ artifacts = self._CommonDownloaderSetup(ignore_background=True)
d = self._CreateArtifactDownloader(artifacts)
self.mox.ReplayAll()
d.Download(self.archive_url_prefix, background=True)
@@ -161,7 +164,7 @@
def testInteractionWithDevserver(self):
"""Tests interaction between the downloader and devserver methods."""
- artifacts = self._CommonDownloaderSetup()
+ artifacts = self._CommonDownloaderSetup(ignore_background=True)
devserver_util.GatherArtifactDownloads(
self._work_dir, self.archive_url_prefix, self.build,
self._work_dir).AndReturn(artifacts)
@@ -171,12 +174,6 @@
devserver.updater = FakeUpdater()
- # Downloads non-synchronous artifacts second.
- for index, artifact in enumerate(artifacts):
- if index % 2 != 0:
- artifact.Download()
- artifact.Stage()
-
self.mox.ReplayAll()
dev = devserver.DevServerRoot()
status = dev.download(archive_url=self.archive_url_prefix)
@@ -229,7 +226,7 @@
def _ClassUnderTest(self):
return downloader.SymbolDownloader
- def _GenerateArtifacts(self):
+ def _GenerateArtifacts(self, unused_ignore_background):
"""Instantiate artifact mocks and set expectations on them.
Sets up a DebugTarball and sets up expectation that it will be