Merge lp:~soren/nova/fix-unittest into lp:~hudson-openstack/nova/trunk

Proposed by Soren Hansen
Status: Merged
Approved by: Jay Pipes
Approved revision: 673
Merged at revision: 673
Proposed branch: lp:~soren/nova/fix-unittest
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 52 lines (+15/-20)
1 file modified
nova/tests/test_api.py (+15/-20)
To merge this branch: bzr merge lp:~soren/nova/fix-unittest
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Ed Leafe (community) Approve
Thierry Carrez (community) Approve
Review via email: mp+49788@code.launchpad.net

Commit message

Fix sporadically failing unittests.

Description of the change

It turns out the failing unittests from the last couple of days weren't racy. They were caused by a difference in ordering depending on the randomly chosen name for the security group used in the tests.

This patch makes sure that we're working on the right groups in the latter half these unit tests.

To post a comment you must log in.
Revision history for this message
Ed Leafe (ed-leafe) wrote :

This might be cleaner:

group = [grp for grp in rv if grp.name == security_group_name][0]

It eliminates the iteration loop, and would have avoided the problem in the first place.

Revision history for this message
Soren Hansen (soren) wrote :

2011/2/15 Ed Leafe <email address hidden>:
> This might be cleaner:
>
> group = [grp for grp in rv if grp.name == security_group_name][0]
>
> It eliminates the iteration loop, and would have avoided the problem in the first place.

Yup, looks good. Thanks.

--
Soren Hansen        | http://linux2go.dk/
Ubuntu Developer    | http://www.ubuntu.com/
OpenStack Developer | http://www.openstack.org/

lp:~soren/nova/fix-unittest updated
673. By Soren Hansen

Beautify it a little bit, thanks to dabo.

Revision history for this message
Thierry Carrez (ttx) wrote :

Let's get rid of random test failures

review: Approve
Revision history for this message
Ed Leafe (ed-leafe) wrote :

lgtm

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

aw, random test failures are just so much fun to diagnose, though...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/tests/test_api.py'
--- nova/tests/test_api.py 2011-01-27 14:45:24 +0000
+++ nova/tests/test_api.py 2011-02-15 12:22:10 +0000
@@ -248,16 +248,14 @@
248 self.mox.ReplayAll()248 self.mox.ReplayAll()
249249
250 rv = self.ec2.get_all_security_groups()250 rv = self.ec2.get_all_security_groups()
251 # I don't bother checkng that we actually find it here,251
252 # because the create/delete unit test further up should252 group = [grp for grp in rv if grp.name == security_group_name][0]
253 # be good enough for that.253
254 for group in rv:254 self.assertEquals(len(group.rules), 1)
255 if group.name == security_group_name:255 self.assertEquals(int(group.rules[0].from_port), 80)
256 self.assertEquals(len(group.rules), 1)256 self.assertEquals(int(group.rules[0].to_port), 81)
257 self.assertEquals(int(group.rules[0].from_port), 80)257 self.assertEquals(len(group.rules[0].grants), 1)
258 self.assertEquals(int(group.rules[0].to_port), 81)258 self.assertEquals(str(group.rules[0].grants[0]), '0.0.0.0/0')
259 self.assertEquals(len(group.rules[0].grants), 1)
260 self.assertEquals(str(group.rules[0].grants[0]), '0.0.0.0/0')
261259
262 self.expect_http()260 self.expect_http()
263 self.mox.ReplayAll()261 self.mox.ReplayAll()
@@ -314,16 +312,13 @@
314 self.mox.ReplayAll()312 self.mox.ReplayAll()
315313
316 rv = self.ec2.get_all_security_groups()314 rv = self.ec2.get_all_security_groups()
317 # I don't bother checkng that we actually find it here,315
318 # because the create/delete unit test further up should316 group = [grp for grp in rv if grp.name == security_group_name][0]
319 # be good enough for that.317 self.assertEquals(len(group.rules), 1)
320 for group in rv:318 self.assertEquals(int(group.rules[0].from_port), 80)
321 if group.name == security_group_name:319 self.assertEquals(int(group.rules[0].to_port), 81)
322 self.assertEquals(len(group.rules), 1)320 self.assertEquals(len(group.rules[0].grants), 1)
323 self.assertEquals(int(group.rules[0].from_port), 80)321 self.assertEquals(str(group.rules[0].grants[0]), '::/0')
324 self.assertEquals(int(group.rules[0].to_port), 81)
325 self.assertEquals(len(group.rules[0].grants), 1)
326 self.assertEquals(str(group.rules[0].grants[0]), '::/0')
327322
328 self.expect_http()323 self.expect_http()
329 self.mox.ReplayAll()324 self.mox.ReplayAll()