diff --git a/pkg/index/index_test.go b/pkg/index/index_test.go index 0dfee3f95..85d2c1ba2 100644 --- a/pkg/index/index_test.go +++ b/pkg/index/index_test.go @@ -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) } diff --git a/pkg/index/mongoindex.go b/pkg/index/mongoindex.go index eb13239f3..630162250 100644 --- a/pkg/index/mongoindex.go +++ b/pkg/index/mongoindex.go @@ -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 }