aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-11-30 21:10:52 +1030
committerMatthew Draper <matthew@trebex.net>2016-11-30 21:10:52 +1030
commit0e97cd1a0d3e7dbe2b99eb111e005d7c9d7002b7 (patch)
tree62085e54ee51b212c86efe35c623c9ebf67417ff /activejob/test
parent160387bca473c888653849b96e0ef54eb4efe7c9 (diff)
downloadrails-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')
-rw-r--r--activejob/test/support/integration/dummy_app_template.rb3
-rw-r--r--activejob/test/support/integration/helper.rb1
2 files changed, 3 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
diff --git a/activejob/test/support/integration/helper.rb b/activejob/test/support/integration/helper.rb
index 1aaee2c809..626b932cce 100644
--- a/activejob/test/support/integration/helper.rb
+++ b/activejob/test/support/integration/helper.rb
@@ -5,6 +5,7 @@ ActiveJob::Base.queue_name_prefix = nil
require "rails/generators/rails/app/app_generator"
+require "tmpdir"
dummy_app_path = Dir.mktmpdir + "/dummy"
dummy_app_template = File.expand_path("../dummy_app_template.rb", __FILE__)
args = Rails::Generators::ARGVScrubber.new(["new", dummy_app_path, "--skip-gemfile", "--skip-bundle",