From 0e97cd1a0d3e7dbe2b99eb111e005d7c9d7002b7 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Wed, 30 Nov 2016 21:10:52 +1030 Subject: Avoid race condition in AJ integration tests Make sure the file doesn't exist until we've finished writing it. --- activejob/test/support/integration/dummy_app_template.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activejob/test/support/integration/dummy_app_template.rb') diff --git a/activejob/test/support/integration/dummy_app_template.rb b/activejob/test/support/integration/dummy_app_template.rb index 62f6fa13f6..29a5691f30 100644 --- a/activejob/test/support/integration/dummy_app_template.rb +++ b/activejob/test/support/integration/dummy_app_template.rb @@ -18,12 +18,13 @@ class TestJob < ActiveJob::Base queue_as :integration_tests def perform(x) - File.open(Rails.root.join("tmp/\#{x}"), "wb+") do |f| + File.open(Rails.root.join("tmp/\#{x}.new"), "wb+") do |f| f.write Marshal.dump({ "locale" => I18n.locale.to_s || "en", "executed_at" => Time.now.to_r }) end + File.rename(Rails.root.join("tmp/\#{x}.new"), Rails.root.join("tmp/\#{x}")) end end CODE -- cgit v1.2.3