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

Proposed by Soren Hansen on 2011-02-15
Status: Merged
Approved by: Jay Pipes on 2011-02-15
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) 2011-02-15 Approve on 2011-02-15
Ed Leafe (community) Approve on 2011-02-15
Thierry Carrez (community) Approve on 2011-02-15
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.
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.

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 on 2011-02-15
673. By Soren Hansen on 2011-02-15

Beautify it a little bit, thanks to dabo.

Thierry Carrez (ttx) wrote :

Let's get rid of random test failures

review: Approve
Ed Leafe (ed-leafe) wrote :

lgtm

review: Approve
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
1=== modified file 'nova/tests/test_api.py'
2--- nova/tests/test_api.py 2011-01-27 14:45:24 +0000
3+++ nova/tests/test_api.py 2011-02-15 12:22:10 +0000
4@@ -248,16 +248,14 @@
5 self.mox.ReplayAll()
6
7 rv = self.ec2.get_all_security_groups()
8- # I don't bother checkng that we actually find it here,
9- # because the create/delete unit test further up should
10- # be good enough for that.
11- for group in rv:
12- if group.name == security_group_name:
13- self.assertEquals(len(group.rules), 1)
14- self.assertEquals(int(group.rules[0].from_port), 80)
15- self.assertEquals(int(group.rules[0].to_port), 81)
16- self.assertEquals(len(group.rules[0].grants), 1)
17- self.assertEquals(str(group.rules[0].grants[0]), '0.0.0.0/0')
18+
19+ group = [grp for grp in rv if grp.name == security_group_name][0]
20+
21+ self.assertEquals(len(group.rules), 1)
22+ self.assertEquals(int(group.rules[0].from_port), 80)
23+ self.assertEquals(int(group.rules[0].to_port), 81)
24+ self.assertEquals(len(group.rules[0].grants), 1)
25+ self.assertEquals(str(group.rules[0].grants[0]), '0.0.0.0/0')
26
27 self.expect_http()
28 self.mox.ReplayAll()
29@@ -314,16 +312,13 @@
30 self.mox.ReplayAll()
31
32 rv = self.ec2.get_all_security_groups()
33- # I don't bother checkng that we actually find it here,
34- # because the create/delete unit test further up should
35- # be good enough for that.
36- for group in rv:
37- if group.name == security_group_name:
38- self.assertEquals(len(group.rules), 1)
39- self.assertEquals(int(group.rules[0].from_port), 80)
40- self.assertEquals(int(group.rules[0].to_port), 81)
41- self.assertEquals(len(group.rules[0].grants), 1)
42- self.assertEquals(str(group.rules[0].grants[0]), '::/0')
43+
44+ group = [grp for grp in rv if grp.name == security_group_name][0]
45+ self.assertEquals(len(group.rules), 1)
46+ self.assertEquals(int(group.rules[0].from_port), 80)
47+ self.assertEquals(int(group.rules[0].to_port), 81)
48+ self.assertEquals(len(group.rules[0].grants), 1)
49+ self.assertEquals(str(group.rules[0].grants[0]), '::/0')
50
51 self.expect_http()
52 self.mox.ReplayAll()