Commit 40fa5604 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'fix/invalid-storage-cleanup-affecting-test-suite' into 'master'

Make test suite deterministic when storage is involved

## What does this MR do?

This MR fixes our RSpec test harness because one test example could affect subsequent examples if objects created with `let` had associated files stored in `tmp/tests`.

We store files using CarrierWave, but we also have some custom storage rules for CI builds. Some time ago we introduced MR that purged CarrierWave uploads after each run of entire test suite https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3435, but this is not enough, as we should isolate each test example to be able to rely on deterministic test suite.

Not cleaning uploads between each test example run, makes it impossible to know if preconditions are correct before test example starts to run, therefore it makes test examples, that use storage, unreliable. This MR is an attempt to improve that.  

## What are the relevant issue numbers?

Closes #24808

See merge request !7695
parents 5522b9dc 71ad3d29
CarrierWave.root = 'tmp/tests/uploads' CarrierWave.root = 'tmp/tests/uploads'
RSpec.configure do |config| RSpec.configure do |config|
config.after(:suite) do config.after(:each) do
FileUtils.rm_rf('tmp/tests/uploads') FileUtils.rm_rf('tmp/tests/uploads')
end end
end end
RSpec.configure do |config| RSpec.configure do |config|
def builds_path def builds_path
Rails.root.join('tmp/builds') Rails.root.join('tmp/tests/builds')
end end
config.before(:each) do config.before(:suite) do
FileUtils.mkdir_p(builds_path)
FileUtils.touch(File.join(builds_path, ".gitkeep"))
Settings.gitlab_ci['builds_path'] = builds_path Settings.gitlab_ci['builds_path'] = builds_path
end end
config.after(:suite) do config.before(:all) do
Dir[File.join(builds_path, '*')].each do |path| FileUtils.mkdir_p(builds_path)
next if File.basename(path) == '.gitkeep'
FileUtils.rm_rf(path)
end end
config.before(:each) do
FileUtils.rm_rf(builds_path)
FileUtils.mkdir_p(builds_path)
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment