Ely
Ely

Reputation: 11174

Curious one time connection error (MongoDB) on Travis CI for first test case only

tl;dr

Tests pass locally, but on Travis CI the very first test case (order of tests is random) always fails. What could be the cause?

Do you know how I can pinpoint where the error is?


Some info:


Whenever I test locally on my development machine, all tests pass successfully. Example:

Local Repo:

[user]@[machine]:~/ComeMalaka$ rake test Run options: --seed 7888

# Running:

.........................................................................................................................................................................................................................

Finished in 94.316005s, 2.3008 runs/s, 32.2533 assertions/s.

217 runs, 3042 assertions, 0 failures, 0 errors, 0 skips Coverage report generated for MiniTest to /home/elyasin/ComeMalaka/coverage. 362 / 362 LOC (100.0%) covered.
[user]@[machine]:~/ComeMalaka$

On my Travis CI build however only the very first test case always fails with an error and all the other test cases pass. The test cases are executed in random order, so every time the first test case is a different one. But every time the first test case fails with the same error message (Mongo driver mentions authorization error).
I am not able to understand why and I don't have an idea what it could be or how to dig deeper.

Travis-CI builds:

# Running:

E........................................................................................................................................................................................................................

Finished in 101.320161s, 2.1417 runs/s, 30.0138 assertions/s.

  1) Error:
ApplicationControllerTest#test_after_sign_in_path:
Mongo::Auth::Unauthorized: User tester is not authorized to access come_malaka_test.
    test/test_helper.rb:33:in `setup'
    test/controllers/application_controller_test.rb:9:in `setup'

217 runs, 3041 assertions, 0 failures, 1 errors, 0 skips



# Running:

E........................................................................................................................................................................................................................

Finished in 79.807236s, 2.7191 runs/s, 38.0793 assertions/s.

  1) Error:
EventRoutesTest#test_must_route_to_expense_report:
Mongo::Auth::Unauthorized: User tester is not authorized to access come_malaka_test.
    test/test_helper.rb:33:in `setup'

217 runs, 3039 assertions, 0 failures, 1 errors, 0 skips

Upvotes: 0

Views: 239

Answers (2)

Ely
Ely

Reputation: 11174

I am not sure why exactly the problem happened, but I managed to fix it. Since the error message said it was due to authorization. I changed my .travis.yml file and created the test user with roles before starting the tests, e.g.:

- mongo come_malaka_test --eval "db.createUser({user:'user',pwd:'pwd',roles:['readWrite']});"

Since then, I did not have the issue.

Upvotes: 1

Antash
Antash

Reputation: 998

I ran into a similar problem while using Ansible to provision a Trusty box with Mongo - I was getting authorization error on the first connection to Mongo while trying to setup my database.

What helped in my case was to add to my playbook a sleep command (for 30s) just before the setup (and after its installation).

I read about it here: https://github.com/travis-ci/travis-ci/issues/1967

Upvotes: 2

Related Questions