From: Andy Allan Date: Wed, 27 Nov 2019 13:57:49 +0000 (+0100) Subject: Use unique test directories for each trace test X-Git-Tag: live~2802^2~3 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/979a474c682c894125e0fe9ddfc5bae566ad895c Use unique test directories for each trace test This allows tests to be run in parallel, since it avoids deleting some of the symlinks that other tests expect to be there. --- diff --git a/test/controllers/api/traces_controller_test.rb b/test/controllers/api/traces_controller_test.rb index 53964b2db..be5cb16cf 100644 --- a/test/controllers/api/traces_controller_test.rb +++ b/test/controllers/api/traces_controller_test.rb @@ -3,9 +3,20 @@ require "minitest/mock" module Api class TracesControllerTest < ActionController::TestCase + # Use temporary directories with unique names for each test + # This allows the tests to be run in parallel. + def setup + @gpx_trace_dir_orig = Settings.gpx_trace_dir + @gpx_image_dir_orig = Settings.gpx_image_dir + Settings.gpx_trace_dir = Dir.mktmpdir("trace", Rails.root.join("test/gpx")) + Settings.gpx_image_dir = Dir.mktmpdir("image", Rails.root.join("test/gpx")) + end + def teardown - File.unlink(*Dir.glob(File.join(Settings.gpx_trace_dir, "*.gpx"))) - File.unlink(*Dir.glob(File.join(Settings.gpx_image_dir, "*.gif"))) + FileUtils.remove_dir(Settings.gpx_trace_dir) + FileUtils.remove_dir(Settings.gpx_image_dir) + Settings.gpx_trace_dir = @gpx_trace_dir_orig + Settings.gpx_image_dir = @gpx_image_dir_orig end ## diff --git a/test/controllers/traces_controller_test.rb b/test/controllers/traces_controller_test.rb index 312d451d7..0f9a9c1db 100644 --- a/test/controllers/traces_controller_test.rb +++ b/test/controllers/traces_controller_test.rb @@ -2,9 +2,20 @@ require "test_helper" require "minitest/mock" class TracesControllerTest < ActionController::TestCase + # Use temporary directories with unique names for each test + # This allows the tests to be run in parallel. + def setup + @gpx_trace_dir_orig = Settings.gpx_trace_dir + @gpx_image_dir_orig = Settings.gpx_image_dir + Settings.gpx_trace_dir = Dir.mktmpdir("trace", Rails.root.join("test/gpx")) + Settings.gpx_image_dir = Dir.mktmpdir("image", Rails.root.join("test/gpx")) + end + def teardown - File.unlink(*Dir.glob(File.join(Settings.gpx_trace_dir, "*.gpx"))) - File.unlink(*Dir.glob(File.join(Settings.gpx_image_dir, "*.gif"))) + FileUtils.remove_dir(Settings.gpx_trace_dir) + FileUtils.remove_dir(Settings.gpx_image_dir) + Settings.gpx_trace_dir = @gpx_trace_dir_orig + Settings.gpx_image_dir = @gpx_image_dir_orig end ## diff --git a/test/models/trace_test.rb b/test/models/trace_test.rb index e0c65e33e..b610a338a 100644 --- a/test/models/trace_test.rb +++ b/test/models/trace_test.rb @@ -3,9 +3,20 @@ require "gpx" require "minitest/mock" class TraceTest < ActiveSupport::TestCase + # Use temporary directories with unique names for each test + # This allows the tests to be run in parallel. + def setup + @gpx_trace_dir_orig = Settings.gpx_trace_dir + @gpx_image_dir_orig = Settings.gpx_image_dir + Settings.gpx_trace_dir = Dir.mktmpdir("trace", Rails.root.join("test/gpx")) + Settings.gpx_image_dir = Dir.mktmpdir("image", Rails.root.join("test/gpx")) + end + def teardown - File.unlink(*Dir.glob(File.join(Settings.gpx_trace_dir, "*.gpx"))) - File.unlink(*Dir.glob(File.join(Settings.gpx_image_dir, "*.gif"))) + FileUtils.remove_dir(Settings.gpx_trace_dir) + FileUtils.remove_dir(Settings.gpx_image_dir) + Settings.gpx_trace_dir = @gpx_trace_dir_orig + Settings.gpx_image_dir = @gpx_image_dir_orig end def test_visible