Closed nim-nim closed 6 years ago
It looks like you didn't initialize a mgo.Session.
I just executed the unit test
Unit tests are supposed to be autonomous
These are integration tests, which means they will use mongodb installed on the system.
The exec.Cmd, invoking mongod, fails and wraps the error it gets in a panic. That panic is caught in a panic handler, which tries to stop the unstarted DB which causes the nil dereference panic. Ugly for sure, but it does not look like broken tests.
Initial exec.Cmd failing is at:
dbserver.go:72
in DBServer.start
This is most likely a configuration issue on your testing machine, such as mongod not being on the path. Can you ensure mongod can be executed by the user running the test?
The dbtest package is not used very much and we would welcome any contribution, that would make the test setup more robust/debuggable.
Hi @nim-nim
I'm going to close this because it sounds like @tadukurow has found the issue - feel free to reply if there's still something else happening though.
Dom
Hi @domodwyer !
I have the same problem. Mongo is actually in my $PATH but it does not seem to start mongo.
$ which mongod
/usr/local/bin/mongod
$ echo $PATH
/Users/jtbonhomme/.pyenv/shims:/Users/jtbonhomme/.pyenv/shims:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/X11/bin:/usr/local/share/npm/bin:/Users/jtbonhomme/.rvm/bin:/Users/jtbonhomme/Developments/golang/bin:/usr/local/opt/go/libexec/bin
Thank you, JT
I had figured it needed mongod in the path, and as you noted this is not sufficient
As running mongod is a privileged operation on my system, I can't see how I could possibly run this test.
@nim-nim, the dbtest package is used for creating integration tests in other test suites. If you're unable to run mongod to execute dbtest, best to skip them as they will always need to execute local mongo for them to be meaningful.
@jtbonhomme, executing locally works for me, so it's probably some environment issue. I did find a test assertion error which is fixed in #122. I've also updated the server start command to print the error to stderr, before throwing the panic. See second line on the sample output below. If you run the branch, it should give you more insight why mongod could not be executed.
=== RUN TestAll
mongod failed to start: exec: "mongod": executable file not found in $PATH
----------------------------------------------------------------------
PANIC: dbserver_test.go:87: S.TestCheckSessions
... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x105A86A)
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491
in gopanic
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:63
in panicmem
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/signal_unix.go:367
in sigpanic
/usr/local/Cellar/go/1.9.2/libexec/src/os/exec_unix.go:56
in Process.signal
/usr/local/Cellar/go/1.9.2/libexec/src/os/exec.go:121
in Process.Signal
dbserver.go:116
in DBServer.Stop
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491
in gopanic
dbserver.go:74
in DBServer.start
dbserver.go:132
in DBServer.Session
dbserver_test.go:92
in S.TestCheckSessions
/usr/local/Cellar/go/1.9.2/libexec/src/reflect/value.go:302
in Value.Call
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/asm_amd64.s:2337
in goexit
mongod failed to start: exec: "mongod": executable file not found in $PATH
----------------------------------------------------------------------
Thank you, a clearer test failure certainly help (though the test should PASS when its prerequisites can't be set up)
While running unit tests with go 1.9.4 on x86_64 for release 2018.02.20
A unit test should always just work with go test and report sensible results