测试仅在使用 rails、elasticsearch 和 searchkick 的 github 操作上失败
Tests fail only on github actions with rails, elasticsearch and searchkick
Ruby 3.0.3
Rails 7.0.0.alpha2
elasticsearch 7.17.1
searchkick 5.0.3
我的测试都通过了 local
但没有通过 GitHub 操作,我不知道为什么...
您知道如何显示错误 500 的详细信息吗?
这是水豚测试
This is the config that I added
结果
Run echo $ELASTIC_SEARCH_URL
http://localhost:49154
health
green
create index
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 99 100 66 100 33 985 492 --:--:-- --:--:-- --:--:-- 1477
{"acknowledged":true,"shards_acknowledged":true,"index":"iot_log"}read_only_allow_delete
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 67 100 21 100 46 3000 6571 --:--:-- --:--:-- --:--:-- 9571
{"acknowledged":true}watermarks
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 654 100 418 100 236 12294 6941 --:--:-- --:--:-- --:--:-- 19818
{
"acknowledged" : true,
"persistent" : { },
"transient" : {
"cluster" : {
"routing" : {
"allocation" : {
"disk" : {
"watermark" : {
"low" : "50gb",
"flood_stage" : "10gb",
"high" : "20gb"
}
}
}
},
"info" : {
"update" : {
"interval" : "1m"
}
}
}
}
}
Run bundle exec rails test
bundle exec rails test
bundle exec rails test:controllers
# bundle exec rails test test/controllers/companies_controller_test.rb:105
bundle exec rails test:system
shell: /usr/bin/bash -e {0}
env:
RAILS_ENV: test
NODE_ENV: test
ES_HOME: /home/runner/elasticsearch/7.17.1
DB_PASSWORD: postgres
DB_PORT: 5432
REDIS_PORT: 49153
ELASTIC_SEARCH_URL: http://localhost:49154
Running 33 tests in a single process (parallelization threshold is 50)
Run options: --seed 9006
# Running:
F
Failure:
TasksControllerTest#test_should_destroy_task_&_related_permission(s)_where_user_!=_assignee [/home/runner/work/hubflo/hubflo/test/controllers/tasks_controller_test.rb:134]:
Expected response to be a <3XX: redirect>, but was a <500: Internal Server Error>
rails test test/controllers/tasks_controller_test.rb:128
编辑答案
所以我使用了 中的 rescue_from
选项
错误是
#<Searchkick::ImportError: {"type"=>"index_not_found_exception", "reason"=>"no such index [companies_test]", "resource.type"=>"index_expression", "resource.id"=>"companies_test", "index_uuid"=>"_na_", "index"=>"companies_test"} on item with id '650928[31](https://github.com/Hubflo-sas/hubflo/runs/5795678731?check_suite_focus=true#step:16:31)2'>
F
Failure:
CompaniesControllerTest#test_should_destroy_company [/home/runner/work/hubflo/hubflo/test/controllers/companies_controller_test.rb:110]:
Expected response to be a <3XX: redirect>, but was a <500: Internal Server Error>
rails test test/controllers/companies_controller_test.rb:104
我必须 运行 在 运行 测试之前 运行 这个命令 bundle exec rake searchkick:reindex:all
<500: Internal Server Error>
表示您的控制器中出现了一些未被正确挽救的异常。如果您无法在您的开发环境中重现该问题,您可以:
- 要么在控制器的操作中添加一个
begin..rescue
,然后在 rescue 中执行:p $ERROR_INFO.message
($ERROR_INFO
是一个特殊变量,它包含最后一个被拯救的异常,它更具可读性使用方法 $!
def my_controller_action
# ... (business logic)
rescue
p $ERROR_INFO.message
end
您还可以在 ApplicationController
中添加全局 rescue_from
class ApplicationController
rescue_from Exception, with: :my_exception_handler
private
def my_exception_handler
# exception handling logic ( logging to Sentry for example etc.)
end
end
这里有一个更详细的例子from the rails documentation
- 或者,使用 rails minitest,你可以 运行
rails test --backtrace
(来源 here),你可能想在其中使用更多有趣的选项您的 CI,甚至在本地开发时。
Ruby 3.0.3
Rails 7.0.0.alpha2
elasticsearch 7.17.1
searchkick 5.0.3
我的测试都通过了 local
但没有通过 GitHub 操作,我不知道为什么...
您知道如何显示错误 500 的详细信息吗?
这是水豚测试
This is the config that I added
结果
Run echo $ELASTIC_SEARCH_URL
http://localhost:49154
health
green
create index
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 99 100 66 100 33 985 492 --:--:-- --:--:-- --:--:-- 1477
{"acknowledged":true,"shards_acknowledged":true,"index":"iot_log"}read_only_allow_delete
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 67 100 21 100 46 3000 6571 --:--:-- --:--:-- --:--:-- 9571
{"acknowledged":true}watermarks
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 654 100 418 100 236 12294 6941 --:--:-- --:--:-- --:--:-- 19818
{
"acknowledged" : true,
"persistent" : { },
"transient" : {
"cluster" : {
"routing" : {
"allocation" : {
"disk" : {
"watermark" : {
"low" : "50gb",
"flood_stage" : "10gb",
"high" : "20gb"
}
}
}
},
"info" : {
"update" : {
"interval" : "1m"
}
}
}
}
}
Run bundle exec rails test
bundle exec rails test
bundle exec rails test:controllers
# bundle exec rails test test/controllers/companies_controller_test.rb:105
bundle exec rails test:system
shell: /usr/bin/bash -e {0}
env:
RAILS_ENV: test
NODE_ENV: test
ES_HOME: /home/runner/elasticsearch/7.17.1
DB_PASSWORD: postgres
DB_PORT: 5432
REDIS_PORT: 49153
ELASTIC_SEARCH_URL: http://localhost:49154
Running 33 tests in a single process (parallelization threshold is 50)
Run options: --seed 9006
# Running:
F
Failure:
TasksControllerTest#test_should_destroy_task_&_related_permission(s)_where_user_!=_assignee [/home/runner/work/hubflo/hubflo/test/controllers/tasks_controller_test.rb:134]:
Expected response to be a <3XX: redirect>, but was a <500: Internal Server Error>
rails test test/controllers/tasks_controller_test.rb:128
编辑答案
所以我使用了 rescue_from
选项
错误是
#<Searchkick::ImportError: {"type"=>"index_not_found_exception", "reason"=>"no such index [companies_test]", "resource.type"=>"index_expression", "resource.id"=>"companies_test", "index_uuid"=>"_na_", "index"=>"companies_test"} on item with id '650928[31](https://github.com/Hubflo-sas/hubflo/runs/5795678731?check_suite_focus=true#step:16:31)2'>
F
Failure:
CompaniesControllerTest#test_should_destroy_company [/home/runner/work/hubflo/hubflo/test/controllers/companies_controller_test.rb:110]:
Expected response to be a <3XX: redirect>, but was a <500: Internal Server Error>
rails test test/controllers/companies_controller_test.rb:104
我必须 运行 在 运行 测试之前 运行 这个命令 bundle exec rake searchkick:reindex:all
<500: Internal Server Error>
表示您的控制器中出现了一些未被正确挽救的异常。如果您无法在您的开发环境中重现该问题,您可以:
- 要么在控制器的操作中添加一个
begin..rescue
,然后在 rescue 中执行:p $ERROR_INFO.message
($ERROR_INFO
是一个特殊变量,它包含最后一个被拯救的异常,它更具可读性使用方法$!
def my_controller_action
# ... (business logic)
rescue
p $ERROR_INFO.message
end
您还可以在 ApplicationController
中添加全局rescue_from
class ApplicationController
rescue_from Exception, with: :my_exception_handler
private
def my_exception_handler
# exception handling logic ( logging to Sentry for example etc.)
end
end
这里有一个更详细的例子from the rails documentation
- 或者,使用 rails minitest,你可以 运行
rails test --backtrace
(来源 here),你可能想在其中使用更多有趣的选项您的 CI,甚至在本地开发时。