diff options
author | Matthew Draper <matthew@trebex.net> | 2016-11-30 21:10:52 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-11-30 21:10:52 +1030 |
commit | 0e97cd1a0d3e7dbe2b99eb111e005d7c9d7002b7 (patch) | |
tree | 62085e54ee51b212c86efe35c623c9ebf67417ff /activejob/test/support/integration/dummy_app_template.rb | |
parent | 160387bca473c888653849b96e0ef54eb4efe7c9 (diff) | |
download | rails-0e97cd1a0d3e7dbe2b99eb111e005d7c9d7002b7.tar.gz rails-0e97cd1a0d3e7dbe2b99eb111e005d7c9d7002b7.tar.bz2 rails-0e97cd1a0d3e7dbe2b99eb111e005d7c9d7002b7.zip |
Avoid race condition in AJ integration tests
Make sure the file doesn't exist until we've finished writing it.
Diffstat (limited to 'activejob/test/support/integration/dummy_app_template.rb')
-rw-r--r-- | activejob/test/support/integration/dummy_app_template.rb | 3 |
1 files changed, 2 insertions, 1 deletions
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 |