Travis CI 上的好奇一次性连接错误 (MongoDB) 仅适用于第一个测试用例
Curious one time connection error (MongoDB) on Travis CI for first test case only
tl;博士
测试在本地通过,但在 Travis CI 上第一个测试用例(测试顺序是随机的)总是失败。可能是什么原因?
你知道我怎样才能找出错误所在吗?
一些信息:
- Ubuntu Trusty (14.04) 本地/Ubuntu Precise (12.04) on Travis-CI
- Ruby 2.2.0
- Rails 4.2.5
- Mongoid 5.0.1
- Mongo本地和 Travis 上的 DB 3.0.8-CI
- 有什么感兴趣的可以问
每当我在我的开发机器上本地测试时,所有测试都会成功。示例:
本地回购:
[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$
在我的 Travis CI 构建中 只有第一个测试用例总是失败 并且 所有其他测试用例通过。测试用例以随机顺序执行,因此 每次第一个测试用例都是不同的 。 但是每次第一个测试用例失败并显示相同的错误消息(Mongo驱动程序提到授权错误).
我无法理解为什么,也不知道它可能是什么或如何更深入地挖掘。
Travis-CI 构建:
# 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
我 运行 在使用 Ansible 提供带有 Mongo 的 Trusty box 时遇到了类似的问题 - 我在尝试设置我的 Mongo 的第一次连接时遇到授权错误数据库。
对我的情况有帮助的是在设置之前(以及安装之后)向我的剧本添加一个睡眠命令(30 秒)。
我不确定为什么会出现这个问题,但我设法解决了它。由于错误消息说这是由于授权。我更改了 .travis.yml
文件并在开始测试之前创建了具有角色的测试用户,例如:
- mongo come_malaka_test --eval "db.createUser({user:'user',pwd:'pwd',roles:['readWrite']});"
从那以后,我再也没有遇到过这个问题。
tl;博士
测试在本地通过,但在 Travis CI 上第一个测试用例(测试顺序是随机的)总是失败。可能是什么原因?
你知道我怎样才能找出错误所在吗?
一些信息:
- Ubuntu Trusty (14.04) 本地/Ubuntu Precise (12.04) on Travis-CI
- Ruby 2.2.0
- Rails 4.2.5
- Mongoid 5.0.1
- Mongo本地和 Travis 上的 DB 3.0.8-CI
- 有什么感兴趣的可以问
每当我在我的开发机器上本地测试时,所有测试都会成功。示例:
本地回购:
[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$
在我的 Travis CI 构建中 只有第一个测试用例总是失败 并且 所有其他测试用例通过。测试用例以随机顺序执行,因此 每次第一个测试用例都是不同的 。 但是每次第一个测试用例失败并显示相同的错误消息(Mongo驱动程序提到授权错误).
我无法理解为什么,也不知道它可能是什么或如何更深入地挖掘。
Travis-CI 构建:
# 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
我 运行 在使用 Ansible 提供带有 Mongo 的 Trusty box 时遇到了类似的问题 - 我在尝试设置我的 Mongo 的第一次连接时遇到授权错误数据库。
对我的情况有帮助的是在设置之前(以及安装之后)向我的剧本添加一个睡眠命令(30 秒)。
我不确定为什么会出现这个问题,但我设法解决了它。由于错误消息说这是由于授权。我更改了 .travis.yml
文件并在开始测试之前创建了具有角色的测试用户,例如:
- mongo come_malaka_test --eval "db.createUser({user:'user',pwd:'pwd',roles:['readWrite']});"
从那以后,我再也没有遇到过这个问题。