Code review comment for lp:~axwalk/juju-core/lp1318527-testing-dropdatabases

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

« Back to merge proposal