Merge lp:~elachuni/software-center/test_downloader_fix into lp:software-center

Proposed by Anthony Lenton
Status: Merged
Merged at revision: 2656
Proposed branch: lp:~elachuni/software-center/test_downloader_fix
Merge into: lp:software-center
Diff against target: 13 lines (+2/-1)
1 file modified
test/test_downloader.py (+2/-1)
To merge this branch: bzr merge lp:~elachuni/software-center/test_downloader_fix
Reviewer Review Type Date Requested Status
software-store-developers Pending
Review via email: mp+88706@code.launchpad.net

Description of the change

Overview
========
A really small fix to avoid a test hanging when your proxy settings are funny.

Details
=======
I found test_downloader.py hanging locally. Looking a bit closer, it was because my system proxy settings are set to "Manual", but with a blank hostname. This is apparently different to setting your proxy to "None".

test_downloader.py doesn't call utils.get_http_proxy_string_from_gsettings(), so it isn't that that's broken, and calling this function and setting os.environ['http_proxy'] with the result (like SoftwareCenterAppGtk3._setup_proxy does) as part of the test's setUp didn't sort out the issue either. It seems that SimpleFileDownloader disregards os.environ['http_proxy'] completely, it might be interesting to look into making SimpleFileDownloader look at os.environ['http_proxy'], but I'm not sure where to go for this.

So, for the moment, I've just changed the test so that it doesn't hang (although it'll still fail if you've got your system-wide proxy set to Manual with a blank host).

To post a comment you must log in.
2655. By Anthony Lenton

Removed pointless import.

Revision history for this message
Michael Vogt (mvo) wrote :

Hey Anthony!

Thanks a bunch for your branch and the fix! I merged it, but tweaks it a little bit because in
download_file() there is always a "is-reachable" check before so if the loop has odd timing the
reachable state can change to true before the file-download-complete call is done and thus the
test would fail. I added a proper check for the "error" signal now. The test will still fail
when there is no network, but that is ok I think (for now):

=== modified file 'test/test_downloader.py'
--- test/test_downloader.py 2012-01-16 14:42:49 +0000
+++ test/test_downloader.py 2012-01-17 08:36:04 +0000
@@ -20,8 +20,11 @@
                                 self._cb_image_url_reachable)
         self.downloader.connect("file-download-complete",
                                 self._cb_image_download_complete)
+ self.downloader.connect("error",
+ self._cb_image_download_error)
         self._image_is_reachable = None
         self._image_downloaded_filename = None
+ self._error = False
         if os.path.exists(self.DOWNLOAD_FILENAME):
             os.unlink(self.DOWNLOAD_FILENAME)

@@ -31,6 +34,9 @@
     def _cb_image_download_complete(self, downloader, filename):
         self._image_downloaded_filename = filename

+ def _cb_image_download_error(self, downloader, gerror, exc):
+ self._error = True
+
     def test_download_unreachable(self):
         self.downloader.download_file("http://www.ubuntu.com/really-not-there",
                                       self.DOWNLOAD_FILENAME)
@@ -47,7 +53,8 @@
         self.downloader.download_file("http://www.ubuntu.com",
                                       self.DOWNLOAD_FILENAME)
         main_loop = GObject.main_context_default()
- while self._image_downloaded_filename is None:
+ while (self._image_downloaded_filename is None and
+ not self._error):
             while main_loop.pending():
                 main_loop.iteration()
             time.sleep(0.1)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test/test_downloader.py'
2--- test/test_downloader.py 2012-01-06 14:01:23 +0000
3+++ test/test_downloader.py 2012-01-16 15:10:29 +0000
4@@ -47,7 +47,8 @@
5 self.downloader.download_file("http://www.ubuntu.com",
6 self.DOWNLOAD_FILENAME)
7 main_loop = GObject.main_context_default()
8- while self._image_downloaded_filename is None:
9+ while (self._image_downloaded_filename is None and
10+ self._image_is_reachable != False):
11 while main_loop.pending():
12 main_loop.iteration()
13 time.sleep(0.1)