summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Caiazza <acaiazza@gitlab.com>2018-03-28 17:15:28 +0200
committerAlessio Caiazza <acaiazza@gitlab.com>2018-03-28 17:17:53 +0200
commit42c3595d2df3e5dfd4a58e2611e3cb1023ee4db4 (patch)
treed28d899410665b7bb6083c6aadf902cd3f14f233
parent23790cc40e86613616d0e11edca0bdad84916cd5 (diff)
downloadgitlab-ce-ac/fix-use_file-race.tar.gz
ObjectStorage exclusive lease testac/fix-use_file-race
-rw-r--r--changelogs/unreleased/ac-fix-use_file-race.yml5
-rw-r--r--spec/support/shared_examples/uploaders/object_storage_shared_examples.rb12
-rw-r--r--spec/uploaders/object_storage_spec.rb24
3 files changed, 41 insertions, 0 deletions
diff --git a/changelogs/unreleased/ac-fix-use_file-race.yml b/changelogs/unreleased/ac-fix-use_file-race.yml
new file mode 100644
index 00000000000..f1315d5d50e
--- /dev/null
+++ b/changelogs/unreleased/ac-fix-use_file-race.yml
@@ -0,0 +1,5 @@
+---
+title: Fix data race between ObjectStorage background_upload and Pages publishing
+merge_request:
+author:
+type: fixed
diff --git a/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb b/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb
index d6cf408dbc5..6352f1527cd 100644
--- a/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb
+++ b/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb
@@ -67,6 +67,12 @@ shared_examples "migrates" do |to_store:, from_store: nil|
migrate(to)
end
+
+ it 'executes use_file' do
+ expect(subject).to receive(:unsafe_use_file).once
+
+ subject.use_file
+ end
end
context 'when migrate! is occupied by another process' do
@@ -82,6 +88,12 @@ shared_examples "migrates" do |to_store:, from_store: nil|
expect { migrate(to) }.to raise_error('exclusive lease already taken')
end
+ it 'does not execute use_file' do
+ expect(subject).not_to receive(:unsafe_use_file)
+
+ expect { subject.use_file }.to raise_error('exclusive lease already taken')
+ end
+
after do
Gitlab::ExclusiveLease.cancel(exclusive_lease_key, @uuid)
end
diff --git a/spec/uploaders/object_storage_spec.rb b/spec/uploaders/object_storage_spec.rb
index 1d406c71955..59e02fecbce 100644
--- a/spec/uploaders/object_storage_spec.rb
+++ b/spec/uploaders/object_storage_spec.rb
@@ -308,6 +308,30 @@ describe ObjectStorage do
it { is_expected.to eq(remote_directory) }
end
+ context 'when file is in use' do
+ def when_file_is_in_use
+ uploader.use_file do
+ yield
+ end
+ end
+
+ it 'cannot migrate' do
+ when_file_is_in_use do
+ expect(uploader).not_to receive(:unsafe_migrate!)
+
+ expect { uploader.migrate!(described_class::Store::REMOTE) }.to raise_error('exclusive lease already taken')
+ end
+ end
+
+ it 'cannot use_file' do
+ when_file_is_in_use do
+ expect(uploader).not_to receive(:unsafe_use_file)
+
+ expect { uploader.use_file }.to raise_error('exclusive lease already taken')
+ end
+ end
+ end
+
describe '#fog_credentials' do
let(:connection) { Settingslogic.new("provider" => "AWS") }