From 143a9c44e16fcec54b7b7813a29b2caa3330870b Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Wed, 24 Mar 2021 15:50:17 +0000 Subject: [PATCH] Ensure that the namespaced collections in the logs db are removed Tests create namespaced (by UUID) capped collections for their logs. These collections must be removed at teardown; otherwise, their number will grow without any bound and cause sequential teardowns to take longer and longer. --- mgo.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mgo.go b/mgo.go index f087af7..035bab3 100644 --- a/mgo.go +++ b/mgo.go @@ -763,6 +763,20 @@ func clearCollections(db *mgo.Database) error { if err != nil { return errors.Trace(err) } + + // The "logs" db is special because tests create namespaced capped + // collections for their logs. Contrary to the other DBs where we + // just flush their contents, we need to drop any collection in the + // "logs" db to avoid an unbounded growth of capped collections. + if db.Name == "logs" { + for _, name := range collectionNames { + if err = db.C(name).DropCollection(); err != nil { + return errors.Trace(err) + } + } + return nil + } + for _, name := range collectionNames { if strings.HasPrefix(name, "system.") { continue