Merge lp:~osomon/webbrowser-app/more-robust-test-server into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 351
Merged at revision: 359
Proposed branch: lp:~osomon/webbrowser-app/more-robust-test-server
Merge into: lp:webbrowser-app
Diff against target: 184 lines (+41/-35)
3 files modified
tests/autopilot/webbrowser_app/tests/__init__.py (+7/-24)
tests/autopilot/webbrowser_app/tests/http_server.py (+22/-2)
tests/autopilot/webbrowser_app/tests/test_progressbar.py (+12/-9)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/more-robust-test-server
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ugo Riboni (community) Approve
Review via email: mp+188019@code.launchpad.net

Commit message

Use a different port for the test server when a zombie process doesn’t release the default one,
and use cleanup functions instead of tearDown() for improved robustness.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ugo Riboni (uriboni) wrote :

All tests pass on my device and the code seems ok. I will only commnent-approve for now as jenkins still has some problems with this MR.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/webbrowser_app/tests/__init__.py'
2--- tests/autopilot/webbrowser_app/tests/__init__.py 2013-09-02 11:07:21 +0000
3+++ tests/autopilot/webbrowser_app/tests/__init__.py 2013-09-30 05:55:13 +0000
4@@ -26,9 +26,6 @@
5 from webbrowser_app.emulators.browser import Browser
6
7
8-HTTP_SERVER_PORT = 8129
9-
10-
11 class BrowserTestCaseBase(AutopilotTestCase):
12
13 """
14@@ -50,14 +47,14 @@
15 def setUp(self):
16 self.pointing_device = Pointer(self.input_device_class.create())
17 super(BrowserTestCaseBase, self).setUp()
18+ self.addCleanup(self.cleanup)
19 if os.path.exists(self.local_location):
20 self.launch_test_local()
21 else:
22 self.launch_test_installed()
23 self.main_window.visible.wait_for(True)
24
25- def tearDown(self):
26- super(BrowserTestCaseBase, self).tearDown()
27+ def cleanup(self):
28 for page in self._temp_pages:
29 try:
30 os.remove(page)
31@@ -199,24 +196,7 @@
32 self.assert_page_eventually_loaded(self.url)
33
34
35-class BrowserTestCaseBaseWithHTTPServer(BrowserTestCaseBase):
36-
37- """
38- A specialization of the common test case class that runs
39- a simple custom HTTP server in a separate thread.
40- """
41-
42- def setUp(self):
43- self.server = http_server.HTTPServerInAThread(HTTP_SERVER_PORT)
44- self.server.start()
45- super(BrowserTestCaseBaseWithHTTPServer, self).setUp()
46-
47- def tearDown(self):
48- super(BrowserTestCaseBaseWithHTTPServer, self).tearDown()
49- self.server.shutdown()
50-
51-
52-class StartOpenRemotePageTestCaseBase(BrowserTestCaseBaseWithHTTPServer):
53+class StartOpenRemotePageTestCaseBase(BrowserTestCaseBase):
54
55 """
56 Helper test class that opens the browser at a remote URL instead of
57@@ -229,7 +209,10 @@
58 """
59
60 def setUp(self):
61- self.base_url = "http://localhost:%d" % HTTP_SERVER_PORT
62+ self.server = http_server.HTTPServerInAThread()
63+ self.server.start()
64+ self.addCleanup(self.server.shutdown)
65+ self.base_url = "http://localhost:%d" % self.server.port
66 self.url = self.base_url + "/loremipsum"
67 self.ARGS = [self.url]
68 super(StartOpenRemotePageTestCaseBase, self).setUp()
69
70=== modified file 'tests/autopilot/webbrowser_app/tests/http_server.py'
71--- tests/autopilot/webbrowser_app/tests/http_server.py 2013-07-04 08:27:16 +0000
72+++ tests/autopilot/webbrowser_app/tests/http_server.py 2013-09-30 05:55:13 +0000
73@@ -7,6 +7,9 @@
74 # by the Free Software Foundation.
75
76 import BaseHTTPServer
77+import errno
78+import os
79+import socket
80 import threading
81 import time
82
83@@ -74,12 +77,29 @@
84 A simple custom HTTP server run in a separate thread.
85 """
86
87- def __init__(self, port):
88+ def __init__(self):
89 super(HTTPServerInAThread, self).__init__()
90- self.server = BaseHTTPServer.HTTPServer(("", port), HTTPRequestHandler)
91+ port = 12345
92+ self.server = None
93+ while self.server is None:
94+ try:
95+ self.server = BaseHTTPServer.HTTPServer(("", port),
96+ HTTPRequestHandler)
97+ except socket.error, error:
98+ if (error.errno == errno.EADDRINUSE):
99+ print "Port %d is already in use" % port
100+ port += 1
101+ else:
102+ print os.strerror(error.errno)
103+ raise
104 self.server.allow_reuse_address = True
105
106+ @property
107+ def port(self):
108+ return self.server.server_port
109+
110 def run(self):
111+ print "now serving on port %d" % self.port
112 self.server.serve_forever()
113
114 def shutdown(self):
115
116=== modified file 'tests/autopilot/webbrowser_app/tests/test_progressbar.py'
117--- tests/autopilot/webbrowser_app/tests/test_progressbar.py 2013-09-16 15:54:21 +0000
118+++ tests/autopilot/webbrowser_app/tests/test_progressbar.py 2013-09-30 05:55:13 +0000
119@@ -14,21 +14,24 @@
120 import unittest
121
122 from webbrowser_app.tests import \
123- BrowserTestCaseBaseWithHTTPServer, \
124- StartOpenRemotePageTestCaseBase, \
125- HTTP_SERVER_PORT
126+ http_server, \
127+ BrowserTestCaseBase, \
128+ StartOpenRemotePageTestCaseBase
129
130
131 LOREMIPSUM = "<p>Lorem ipsum dolor sit amet.</p>"
132
133
134-class TestProgressBarAtStartup(BrowserTestCaseBaseWithHTTPServer):
135+class TestProgressBarAtStartup(BrowserTestCaseBase):
136
137 """Tests that the progress bar (embedded inside the address bar) is
138 initially visible when loading a page."""
139
140 def setUp(self):
141- self.base_url = "http://localhost:%d" % HTTP_SERVER_PORT
142+ self.server = http_server.HTTPServerInAThread()
143+ self.server.start()
144+ self.addCleanup(self.server.shutdown)
145+ self.base_url = "http://localhost:%d" % self.server.port
146 self.url = self.base_url + "/wait/8"
147 self.ARGS = [self.url]
148 super(TestProgressBarAtStartup, self).setUp()
149@@ -49,7 +52,7 @@
150
151 def test_chrome_hides_when_loaded(self):
152 self.assert_chrome_eventually_hidden()
153- url = "http://localhost:%d/wait/3" % HTTP_SERVER_PORT
154+ url = "http://localhost:%d/wait/3" % self.server.port
155 self.go_to_url(url)
156 self.assert_chrome_eventually_shown()
157 self.assert_page_eventually_loaded(url)
158@@ -58,7 +61,7 @@
159 def test_load_page_from_link_reveals_chrome(self):
160 # craft a page that accepts clicks anywhere inside its window
161 style = "'margin: 0; height: 100%'"
162- url = "http://localhost:%d/wait/3" % HTTP_SERVER_PORT
163+ url = "http://localhost:%d/wait/3" % self.server.port
164 script = "'window.location = \"%s\"'" % url
165 html = "<html><body style=%s onclick=%s></body></html>" % \
166 (style, script)
167@@ -74,7 +77,7 @@
168 # simulate user interaction to hide the chrome while loading,
169 # and ensure it doesn’t re-appear when loaded
170 self.assert_chrome_eventually_hidden()
171- url = "http://localhost:%d/wait/3" % HTTP_SERVER_PORT
172+ url = "http://localhost:%d/wait/3" % self.server.port
173 self.go_to_url(url)
174 self.assert_chrome_eventually_shown()
175 webview = self.main_window.get_current_webview()
176@@ -87,7 +90,7 @@
177 # ensure that the chrome is not automatically hidden
178 # when the user interrupts a page that was loading
179 self.assert_chrome_eventually_hidden()
180- url = "http://localhost:%d/wait/5" % HTTP_SERVER_PORT
181+ url = "http://localhost:%d/wait/5" % self.server.port
182 self.go_to_url(url)
183 self.assert_page_eventually_loading()
184 self.assert_chrome_eventually_shown()

Subscribers

People subscribed via source and target branches

to status/vote changes: