-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flakyなテストを2つ修正した #7997
Flakyなテストを2つ修正した #7997
Changes from all commits
1189300
ed5a326
70f5749
c9e8359
19f294e
1342612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,31 +2,31 @@ | |
# ActiveStorage::FixtureSet.blob を使うように変更する | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. こちらを参考に、各フィクスチャの保存先を設定しています。 |
||
# companies | ||
company1_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/1.jpg" %> | ||
company1_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/1.jpg", service_name: "test_fixtures" %> | ||
|
||
company2_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/2.jpg" %> | ||
company2_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/2.jpg", service_name: "test_fixtures" %> | ||
|
||
company3_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/3.jpg" %> | ||
company3_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/3.jpg", service_name: "test_fixtures" %> | ||
|
||
company4_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/4.jpg" %> | ||
company4_logo_blob: <%= ActiveStorage::Blob.fixture filename: "companies/logos/4.jpg", service_name: "test_fixtures" %> | ||
|
||
# users | ||
hatsuno_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/hatsuno.jpg" %> | ||
hatsuno_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/hatsuno.jpg", service_name: "test_fixtures" %> | ||
|
||
komagata_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/komagata.jpg" %> | ||
komagata_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/komagata.jpg", service_name: "test_fixtures" %> | ||
|
||
machida_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/machida.jpg" %> | ||
machida_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/machida.jpg", service_name: "test_fixtures" %> | ||
|
||
mentormentaro_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/mentormentaro.jpg" %> | ||
mentormentaro_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/mentormentaro.jpg", service_name: "test_fixtures" %> | ||
|
||
mineo_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/mineo.jpg" %> | ||
mineo_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/mineo.jpg", service_name: "test_fixtures" %> | ||
|
||
tanaka_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/tanaka.jpg" %> | ||
tanaka_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/tanaka.jpg", service_name: "test_fixtures" %> | ||
|
||
yameo_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/yameo.jpg" %> | ||
yameo_avatar_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/yameo.jpg", service_name: "test_fixtures" %> | ||
|
||
komagata_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/komagata.jpg" %> | ||
komagata_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/komagata.jpg", service_name: "test_fixtures" %> | ||
|
||
machida_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/machida.jpg" %> | ||
machida_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/machida.jpg", service_name: "test_fixtures" %> | ||
|
||
kimuramitai_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/default.jpg" %> | ||
kimuramitai_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/default.jpg", service_name: "test_fixtures" %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,22 @@ class ActiveSupport::TestCase | |
teardown do | ||
ActiveStorage::Current.host = nil | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. こちらを参考にして、並列のプロセスごとに、保存先にそれぞれ番号がふられるように設定しています。 Railsガイドにある書き方はRails7から入った機能です。 |
||
# Rails7になったら以下のように修正する | ||
# parallelize_setup do |i| | ||
# ActiveStorage::Blob.service.root = "#{ActiveStorage::Blob.service.root}/storage-#{i}" | ||
# ActiveStorage::Blob.services.fetch(:test_fixtures).root = "#{ActiveStorage::Blob.services.fetch(:test_fixtures).root}/fixtures-#{i}" | ||
# end | ||
# 参考: https://guides.rubyonrails.org/active_storage_overview.html#discarding-files-created-during-tests | ||
parallelize_setup do |i| | ||
ActiveStorage::Blob.service.instance_variable_set(:@root, "#{ActiveStorage::Blob.service.root}/storage-#{i}") | ||
ActiveStorage::Blob.services.fetch(:test_fixtures).instance_variable_set(:@root, "#{ActiveStorage::Blob.services.fetch(:test_fixtures).root}/fixtures-#{i}") | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. アップロード用保存先フォルダに関しては、Railsガイドには |
||
Minitest.after_run do | ||
FileUtils.rm_rf(ActiveStorage::Blob.service.root) | ||
FileUtils.rm_rf(ActiveStorage::Blob.services.fetch(:test_fixtures).root) | ||
end | ||
end | ||
|
||
class ActionDispatch::IntegrationTest | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下記リンクを参考にfixtures用の保存先を作成しています。
Active Storage の概要 - Railsガイド