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'
RSpec.configure do |config|
config.after(:suite) do
config.after(:each) do
FileUtils.rm_rf('tmp/tests/uploads')
end
end
RSpec.configure do |config|
def builds_path
Rails.root.join('tmp/builds')
Rails.root.join('tmp/tests/builds')
end
config.before(:each) do
FileUtils.mkdir_p(builds_path)
FileUtils.touch(File.join(builds_path, ".gitkeep"))
config.before(:suite) do
Settings.gitlab_ci['builds_path'] = builds_path
end
config.after(:suite) do
Dir[File.join(builds_path, '*')].each do |path|
next if File.basename(path) == '.gitkeep'
config.before(:all) do
FileUtils.mkdir_p(builds_path)
end
FileUtils.rm_rf(path)
end
config.before(:each) do
FileUtils.rm_rf(builds_path)
FileUtils.mkdir_p(builds_path)
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