Merge lp:~townsend/unity/fix-ap-mouse-infinite-loop into lp:unity

Proposed by Christopher Townsend
Status: Merged
Approved by: Francis Ginther
Approved revision: no longer in the source branch.
Merged at revision: 3512
Proposed branch: lp:~townsend/unity/fix-ap-mouse-infinite-loop
Merge into: lp:unity
Diff against target: 108 lines (+23/-38)
2 files modified
tests/autopilot/unity/emulators/launcher.py (+21/-36)
tests/autopilot/unity/tests/launcher/test_scroll.py (+2/-2)
To merge this branch: bzr merge lp:~townsend/unity/fix-ap-mouse-infinite-loop
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Brandon Schaefer (community) Approve
Review via email: mp+186070@code.launchpad.net

Commit message

Make the mouse movement infinite while loop into a for loop and only iterate 10 times w/ a 0.5 second delay between movements. Raise an error if the correct icon is not found when the loop terminates.
Consolidate the autoscroll_to_icon() function into the move_mouse_to_icon() function and change move_mouse_to_icon() to handle autoscrolling offsets.

Description of the change

= Issue =
Some AP tests will move the mouse to a specific icon. The function to handle moving the mouse to the icon contained an infinite loop to move the mouse. The infinite loop was to make sure the Launcher would scroll since the icon could be off the screen. However, certain conditions can cause the Launcher to not scroll which led to a very long delay in the AP test of 7200 seconds! This also led to no movie of the failure to be created.

= Fix =
Instead of using an infinite while loop, now instead use a for loop and only iterate 10 times with a 0.5 second delay between movements. If the icon is not found after the loop terminates, raise an error which will fail the test and we should have a movie of what was causing the Launcher to not scroll.

I also consolidated the autoscroll_to_icon(0 function into the move_mouse_to_icon() function and added support to the move_mouse_to_icon() function to handle autscrolling offsets.

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
Brandon Schaefer (brandontschaefer) wrote :

LGTM

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) :
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/unity/emulators/launcher.py'
2--- tests/autopilot/unity/emulators/launcher.py 2013-09-12 15:56:41 +0000
3+++ tests/autopilot/unity/emulators/launcher.py 2013-09-17 15:16:51 +0000
4@@ -121,16 +121,28 @@
5 logger.debug("Moving mouse to center of launcher.")
6 self._mouse.move(target_x, target_y)
7
8- def move_mouse_to_icon(self, icon):
9- # The icon may be off the bottom of screen, so we do this in a loop:
10- while 1:
11- target_x = icon.center_x + self.x
12- target_y = icon.center_y
13+ def move_mouse_to_icon(self, icon, autoscroll_offset=0):
14+ """Move the mouse to a specific icon."""
15+ (x, y, w, h) = self.geometry
16+ found = False
17+
18+ # Only try 10 times (5 secs.) before giving up.
19+ for i in xrange(0, 10):
20+ mouse_x = target_x = icon.center_x + self.x
21+ mouse_y = target_y = icon.center_y
22+ if target_y > h:
23+ mouse_y = h + y - autoscroll_offset
24+ elif target_y < 0:
25+ mouse_y = y + autoscroll_offset
26 if self._mouse.x == target_x and self._mouse.y == target_y:
27+ found = True
28 break
29- self._mouse.move(target_x, target_y)
30+ self._mouse.move(mouse_x, mouse_y)
31 sleep(0.5)
32
33+ if not found:
34+ raise RuntimeError("Could not move mouse to the icon")
35+
36 def mouse_reveal_launcher(self):
37 """Reveal this launcher with the mouse.
38
39@@ -309,17 +321,11 @@
40
41 logger.debug("Clicking launcher icon %r on monitor %d with mouse button %d",
42 icon, self.monitor, button)
43+
44 self.mouse_reveal_launcher()
45-
46- # The icon may be off the screen, so we do this in a loop:
47- while 1:
48- target_x = icon.center_x + self.x
49- target_y = icon.center_y
50- if self._mouse.x == target_x and self._mouse.y == target_y:
51- break
52- self._mouse.move(target_x, target_y )
53- sleep(1)
54+ self.move_mouse_to_icon(icon)
55 self._mouse.click(button)
56+
57 if (move_mouse_after):
58 self.move_mouse_to_right_of_launcher()
59
60@@ -422,27 +428,6 @@
61 pin_item = quicklist.get_quicklist_item_by_text('Unlock from Launcher')
62 quicklist.click_item(pin_item)
63
64- def autoscroll_to_icon(self, icon, autoscroll_offset=0):
65- """Moves the mouse to the autoscroll zone to scroll the Launcher to the icon
66- in question.
67-
68- autoscroll_offet is the offset, in number of pixels, from the end of the
69- autoscroll zone where is the autoscroll zone is currently 24 pixels high.
70- """
71- (x, y, w, h) = self.geometry
72-
73- while 1:
74- mouse_x = target_x = icon.center_x + self.x
75- mouse_y = target_y = icon.center_y
76- if target_y > h:
77- mouse_y = h + y - autoscroll_offset
78- elif target_y < 0:
79- mouse_y = y + autoscroll_offset
80- if self._mouse.x == target_x and self._mouse.y == target_y:
81- break
82- self._mouse.move(mouse_x, mouse_y)
83- sleep(0.5)
84-
85 @property
86 def geometry(self):
87 """Returns a tuple of (x,y,w,h) for the current launcher."""
88
89=== modified file 'tests/autopilot/unity/tests/launcher/test_scroll.py'
90--- tests/autopilot/unity/tests/launcher/test_scroll.py 2013-05-20 10:36:31 +0000
91+++ tests/autopilot/unity/tests/launcher/test_scroll.py 2013-09-17 15:16:51 +0000
92@@ -58,7 +58,7 @@
93 self.assertThat(last_icon.center_y, Eventually(GreaterThan(h)))
94
95 # Autoscroll to the last icon
96- launcher_instance.autoscroll_to_icon(last_icon, autoscroll_offset)
97+ launcher_instance.move_mouse_to_icon(last_icon, autoscroll_offset)
98
99 (x_fin, y_fin) = self.mouse.position()
100
101@@ -90,7 +90,7 @@
102 self.assertThat(first_icon.center_y, Eventually(LessThan(y)))
103
104 # Autoscroll to the first icon
105- launcher_instance.autoscroll_to_icon(first_icon, autoscroll_offset)
106+ launcher_instance.move_mouse_to_icon(first_icon, autoscroll_offset)
107
108 (x_fin, y_fin) = self.mouse.position()
109