Skip to content

Commit c1418ba

Browse files
authored
Merge pull request #133 from axw/testing-mgo-default-storageengine
testing: default to mmapv1 only on x86(_64) When building mongod, mmapv1 is only enabled by default for x86 and x86_64. Change the tests to use wiredTiger on other architectures.
2 parents 799dbfe + f506009 commit c1418ba

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

mgo.go

+18-10
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ const (
6464

6565
// The default password to use when connecting to the mongo database.
6666
DefaultMongoPassword = "conn-from-name-secret"
67-
68-
// defaultMongoStorageEngine is the default storage engine to use
69-
// in Mongo 3.2 onwards for tests. We default to mmapv1 (vs. the
70-
// mongo default of wiredTiger) for the best performance in tests,
71-
// but make it configurable.
72-
defaultMongoStorageEngine = "mmapv1"
7367
)
7468

7569
// Certs holds the certificates and keys required to make a secure
@@ -267,11 +261,10 @@ func (inst *MgoInstance) run() error {
267261
mgoargs = append(mgoargs, "--nojournal")
268262
}
269263
if version.Compare(storageEngineMongoVersion) >= 0 {
270-
storageEngine := os.Getenv("JUJU_MONGO_STORAGE_ENGINE")
271-
if storageEngine == "" {
272-
storageEngine = defaultMongoStorageEngine
264+
storageEngine := mongoStorageEngine()
265+
if storageEngine != "" {
266+
mgoargs = append(mgoargs, "--storageEngine", storageEngine)
273267
}
274-
mgoargs = append(mgoargs, "--storageEngine", storageEngine)
275268
}
276269

277270
if inst.Params != nil {
@@ -339,6 +332,21 @@ func (inst *MgoInstance) run() error {
339332
return nil
340333
}
341334

335+
func mongoStorageEngine() string {
336+
storageEngine := os.Getenv("JUJU_MONGO_STORAGE_ENGINE")
337+
if storageEngine != "" {
338+
return storageEngine
339+
}
340+
switch runtime.GOARCH {
341+
case "386", "amd64":
342+
// On x86(_64), mmapv1 should always be available. If not
343+
// overridden via the environment variable above, we use
344+
// mmapv1 by default for the best performance in tests.
345+
return "mmapv1"
346+
}
347+
return "" // use the default
348+
}
349+
342350
// mongodCache looks up mongod path and version and caches the result.
343351
type mongodCache struct {
344352
sync.Mutex

0 commit comments

Comments
 (0)