CascadiaJS
CascadiaJS

Reputation: 2505

How do you get Travis CI to start mongodb?

I have created a .travis.yml file that is correct as far as I can tell, but when Travis CI runs the test (it's a new project, so I only have one) I get an error that there is no database running

connection error:  { [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect ECONNREFUSED' }

I added a pretest script to start mongo and now I can run my local test without starting mongo and it passes, but with Travis CI it gets the error:

ERROR: child process failed, exited with error number 100

My .travis.yml file looks like this:

language: node_js
node_js:
  "0.10"

services:
- mongodb

and here's my scripts from the package.json:

  "scripts": {
    "pretest": "mongod --fork --logpath /dev/null",
    "test": "./node_modules/mocha/bin/mocha test/**/*.js",
    "posttest": "mongo admin --eval 'db.shutdownServer()' > /dev/null",
    "start": "node server.js"
  },

I tried to put links to travis, but I'm new so I can only put one link, so I'll put the link to my repo, so you can get those links from there if you want to see the full travis failure: https://github.com/mrbgit/short-stories/tree/tests-for-story-post

Any help with this would be great. I'm new to Stack Overflow, so please let me know if you need more info.

Thanks for the help!

Upvotes: 2

Views: 3272

Answers (2)

Dominic Jodoin
Dominic Jodoin

Reputation: 2538

I looked at your repo and it looks like you have two files:

  • one named .travis.yml which doesn't start MongoDB
  • one named travis.yml (notice there is no leading dot (i.e..) here) which starts MongoDB with the code listed above.

Travis CI only picks up the file named .travis.yml. So make sure the right one.

I forked your repo and did a test with a fixed .travis.yml and seems to have worked.

Hope this helps!

Upvotes: 3

RavisMsk
RavisMsk

Reputation: 86

I thing that link to official docs may be kind of useful.

Seems like you don't need to manually start mongodb as you do in pretest. Maybe, I don't actually know, your pretest is being ran first, and after it travis tries to start mongodb, but it's already running, and it hits error and stops process.

Also I found this thread. The problem was in owner of mongodb data directory. It was under root, but mongodb was started w/o sudo. If you're running mongodb by yourself (as you do in pretest), you can manually specify --dbpath for directory with acceptable rights for your user.

Upvotes: 0

Related Questions