Rspec Rails 5 ActiveStorage如何等待所有线程完成

Rspec Rails 5 ActiveStorage如何等待所有线程完成,rspec,rails-activestorage,ruby-on-rails-5.2,Rspec,Rails Activestorage,Ruby On Rails 5.2,首先,让我描述一下问题。我使用RSpec运行一个脚本来生成一些测试数据 RAILS_ENV=development rspec spec/dev/food/food_upload.rb 脚本如下所示 image = fixture_file_upload(Rails.root.join('spec', 'resources', 'test2.png'), 'image/png') (0..200).each { food = FactoryBot.build

首先,让我描述一下问题。我使用RSpec运行一个脚本来生成一些测试数据

RAILS_ENV=development rspec spec/dev/food/food_upload.rb
脚本如下所示

    image = fixture_file_upload(Rails.root.join('spec', 'resources', 'test2.png'), 'image/png')

    (0..200).each { 
        food = FactoryBot.build :food
        p "Loading #{food.name}"
        expect {
            post :upload, params: {
                "foodUpload_foodName"=> food.name,
                "foodUpload_image"=> image
            }
        }.to change(Food, :count).by(1)
        .and change(Image, :count).by(1)
此脚本将数据发送到FoodController,后者随后添加更多食物项。每个食物都使用ActiveStorage来保存图像

问题是这个脚本完成得太快了,正如我发现的,ActiveStorage产生了新的线程来处理图像。因此,我有许多未完成的图像,在尝试加载图像时,它会显示“minimagick::invalid error with message Unroxed image header”


目前,我正在使用睡眠(5分钟)来处理这个问题。我只是想知道是否有其他方法可以正确执行。

答案是将
image=fixture\u file\u upload()
移动到(0..200).每个{}循环中。花了我一天时间