github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/testing/mgo.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package testing
     5  
     6  import (
     7  	"testing"
     8  	"time"
     9  
    10  	mgotesting "github.com/juju/mgo/v3/testing"
    11  )
    12  
    13  // MgoTestPackage should be called to register the tests for any package
    14  // that requires a connection to a MongoDB server.
    15  //
    16  // The server will be configured without SSL enabled, which slows down
    17  // tests. For tests that care about security (which should be few), use
    18  // MgoSSLTestPackage.
    19  func MgoTestPackage(t *testing.T) {
    20  	mgotesting.MgoServer.EnableReplicaSet = true
    21  	// Tests tend to cause enough contention that the default lock request
    22  	// timeout of 5ms is not enough. We may need to consider increasing the
    23  	// value for production also.
    24  	mgotesting.MgoServer.MaxTransactionLockRequestTimeout = 20 * time.Millisecond
    25  	mgotesting.MgoTestPackage(t, nil)
    26  }
    27  
    28  // MgoSSLTestPackage should be called to register the tests for any package
    29  // that requires a secure (SSL) connection to a MongoDB server.
    30  func MgoSSLTestPackage(t *testing.T) {
    31  	mgotesting.MgoServer.EnableReplicaSet = true
    32  	// Tests tend to cause enough contention that the default lock request
    33  	// timeout of 5ms is not enough. We may need to consider increasing the
    34  	// value for production also.
    35  	mgotesting.MgoServer.MaxTransactionLockRequestTimeout = 20 * time.Millisecond
    36  	mgotesting.MgoTestPackage(t, Certs)
    37  }