Merge lp:~axwalk/juju-core/lp1318527-testing-dropdatabases into lp:~go-bot/juju-core/trunk

Proposed by Andrew Wilkins
Status: Merged
Approved by: Andrew Wilkins
Approved revision: no longer in the source branch.
Merged at revision: 2730
Proposed branch: lp:~axwalk/juju-core/lp1318527-testing-dropdatabases
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 37 lines (+20/-0)
1 file modified
testing/mgo.go (+20/-0)
To merge this branch: bzr merge lp:~axwalk/juju-core/lp1318527-testing-dropdatabases
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+219462@code.launchpad.net

Commit message

testing: drop databases before each Mgo test

Previously the store package had its own mgo
suite, which was largely the same as the one
in juju-core/testing. It also had code to drop
the non-admin databases before each test case,
which I did not carry over when migrating. This
caused flakeyness.

Fixes lp:1318527

https://codereview.appspot.com/94460045/

Description of the change

testing: drop databases before each Mgo test

Previously the store package had its own mgo
suite, which was largely the same as the one
in juju-core/testing. It also had code to drop
the non-admin databases before each test case,
which I did not carry over when migrating. This
caused flakeyness.

Fixes lp:1318527

https://codereview.appspot.com/94460045/

To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote :

Reviewers: mp+219462_code.launchpad.net,

Message:
Please take a look.

Description:
testing: drop databases before each Mgo test

Previously the store package had its own mgo
suite, which was largely the same as the one
in juju-core/testing. It also had code to drop
the non-admin databases before each test case,
which I did not carry over when migrating. This
caused flakeyness.

Fixes lp:1318527

https://code.launchpad.net/~axwalk/juju-core/lp1318527-testing-dropdatabases/+merge/219462

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/94460045/

Affected files (+22, -0 lines):
   A [revision details]
   M testing/mgo.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20140514033806-f68i80gbds824vtw
+New revision: <email address hidden>

Index: testing/mgo.go
=== modified file 'testing/mgo.go'
--- testing/mgo.go 2014-05-12 07:59:38 +0000
+++ testing/mgo.go 2014-05-14 07:25:05 +0000
@@ -401,6 +401,7 @@
  func (s *MgoSuite) SetUpTest(c *gc.C) {
   mgo.ResetStats()
   s.Session = MgoServer.MustDial()
+ dropAll(s.Session)
  }

  // Reset deletes all content from the MongoDB server and panics if it
encounters
@@ -441,6 +442,25 @@
   }
  }

+// dropAll drops all databases apart from admin, local and config.
+func dropAll(session *mgo.Session) (err error) {
+ names, err := session.DatabaseNames()
+ if err != nil {
+ return err
+ }
+ for _, name := range names {
+ switch name {
+ case "admin", "local", "config":
+ default:
+ err = session.DB(name).DropDatabase()
+ if err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+
  // resetAdminPasswordAndFetchDBNames logs into the database with a
  // plausible password and returns all the database's db names. We need
  // to try several passwords because we don't know what state the mongo

Revision history for this message
William Reade (fwereade) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testing/mgo.go'
2--- testing/mgo.go 2014-05-12 07:59:38 +0000
3+++ testing/mgo.go 2014-05-14 07:29:10 +0000
4@@ -401,6 +401,7 @@
5 func (s *MgoSuite) SetUpTest(c *gc.C) {
6 mgo.ResetStats()
7 s.Session = MgoServer.MustDial()
8+ dropAll(s.Session)
9 }
10
11 // Reset deletes all content from the MongoDB server and panics if it encounters
12@@ -441,6 +442,25 @@
13 }
14 }
15
16+// dropAll drops all databases apart from admin, local and config.
17+func dropAll(session *mgo.Session) (err error) {
18+ names, err := session.DatabaseNames()
19+ if err != nil {
20+ return err
21+ }
22+ for _, name := range names {
23+ switch name {
24+ case "admin", "local", "config":
25+ default:
26+ err = session.DB(name).DropDatabase()
27+ if err != nil {
28+ return err
29+ }
30+ }
31+ }
32+ return nil
33+}
34+
35 // resetAdminPasswordAndFetchDBNames logs into the database with a
36 // plausible password and returns all the database's db names. We need
37 // to try several passwords because we don't know what state the mongo

Subscribers

People subscribed via source and target branches

to status/vote changes: