mongo tests now actually fail when no mongodb running

Change-Id: I470c2184c620fa0bba02001ea6877a95cf53d9d6
This commit is contained in:
mpl 2012-02-21 15:25:29 +01:00
parent d40c9dce1d
commit 5a2c060409
2 changed files with 5 additions and 9 deletions

View File

@ -144,8 +144,6 @@ func (id *IndexDeps) UploadFile(fileName string, contents string) (fileRef, whol
}
func NewIndexDeps(index *Index) *IndexDeps {
// TODO(mpl): figure out why this wrong path wasn't making the mongo tests fail
// secretRingFile := "../../../../lib/go/camli/jsonsign/testdata/test-secring.gpg"
secretRingFile := "../jsonsign/testdata/test-secring.gpg"
pubKey := &test.Blob{Contents: `-----BEGIN PGP PUBLIC KEY BLOCK-----
@ -183,7 +181,7 @@ func checkMongoUp() {
mgw := &MongoWrapper{
Servers: "localhost",
}
mongoNotAvailable = !mgw.TestConnection(1e9)
mongoNotAvailable = !mgw.TestConnection(500 * time.Millisecond)
}
func initMongoIndex() *Index {
@ -209,8 +207,7 @@ func (mongoTester) test(t *testing.T, tfn func(*testing.T, func() *Index)) {
once.Do(checkMongoUp)
if mongoNotAvailable {
err := errors.New("Not running; start a mongoDB daemon on the standard port (27017). The \"keys\" collection in the \"camlitest\" database will be used.")
t.Logf("Mongo not available locally for testing: %v", err)
return
t.Fatalf("Mongo not available locally for testing: %v", err)
}
tfn(t, initMongoIndex)
}

View File

@ -51,14 +51,13 @@ type MongoWrapper struct {
}
// Note that Ping won't work with old (1.2) mongo servers.
func (mgw *MongoWrapper) TestConnection(timeout int64) bool {
session, err := mgo.Dial(mgw.Servers)
func (mgw *MongoWrapper) TestConnection(timeout time.Duration) bool {
session, err := mgo.DialWithTimeout(mgw.Servers, timeout)
if err != nil {
return false
}
defer session.Close()
t := time.Duration(timeout)
session.SetSyncTimeout(t)
session.SetSyncTimeout(timeout)
if err = session.Ping(); err != nil {
return false
}