Hook up mgo logging and reconnect properly. #110

Merged
merged 1 commit into from Sep 16, 2016

Conversation

Projects
None yet
3 participants
Owner

howbazaar commented Sep 16, 2016

Now the mgo logging is output through loggo to the "mgo" logger.
This means it is now available to be shown, but not shown by default.
To enable in other tests, they can (after logging is set up) set:
loggo.GetLogger("mgo").SetLogLevel(loggo.TRACE)
Also, when the mongo server is changed by either restarting, or other tests killing it, the teardown now reconnects the session, which avoids some of the "no reachable servers" errors we were seeing.

mjs approved these changes Sep 16, 2016

mgo.go
@@ -422,7 +423,16 @@ func MgoTestPackage(t *testing.T, certs *Certs) {
gc.TestingT(t)
}
+// Output implements the mgo log_Logger interface.
+func (s *MgoSuite) Output(calldepth int, message string) error {
@mjs

mjs Sep 16, 2016

I don't mind too much, but this doesn't really belong on the suite. A simpler wrapper type would be cleaner. The logger wouldn't even have to be added as a field on MgoSuite...

mgo.go
@@ -758,6 +770,7 @@ func (inst *MgoInstance) EnsureRunning() error {
// If the server has already been destroyed for testing purposes,
// just start it again.
if inst.Addr() == "" {
+ logger.Infof("restarting mongo instance")
@mjs

mjs Sep 16, 2016

this should probably be debug

+ foundAddress := false
+ for _, addr := range s.Session.LiveServers() {
+ if addr == MgoServer.Addr() {
+ foundAddress = true
Owner

howbazaar commented Sep 16, 2016

$$merge$$

Contributor

jujubot commented Sep 16, 2016

@jujubot jujubot merged commit cad2dd5 into juju:master Sep 16, 2016

@howbazaar howbazaar deleted the howbazaar:reconnect-properly branch Sep 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment