Commit f44665c8 authored by Mike Greiling's avatar Mike Greiling

slow down requests for dropzone uploads to avoid race conditions

parent 9e538fd0
......@@ -7,6 +7,7 @@ module Gitlab
class RequestBlockerMiddleware
@@num_active_requests = Concurrent::AtomicFixnum.new(0)
@@block_requests = Concurrent::AtomicBoolean.new(false)
@@slow_requests = Concurrent::AtomicBoolean.new(false)
# Returns the number of requests the server is currently processing.
def self.num_active_requests
......@@ -19,9 +20,15 @@ module Gitlab
@@block_requests.value = true
end
# Slows down incoming requests (useful for race conditions).
def self.slow_requests!
@@slow_requests.value = true
end
# Allows the server to accept requests again.
def self.allow_requests!
@@block_requests.value = false
@@slow_requests.value = false
end
def initialize(app)
......@@ -33,6 +40,7 @@ module Gitlab
if block_requests?
block_request(env)
else
sleep 0.2 if slow_requests?
@app.call(env)
end
ensure
......@@ -45,6 +53,10 @@ module Gitlab
@@block_requests.true?
end
def slow_requests?
@@slow_requests.true?
end
def block_request(env)
[503, {}, []]
end
......
......@@ -21,6 +21,14 @@ feature 'User uploads file to note' do
end
context 'uploading is in progress' do
before do
Gitlab::Testing::RequestBlockerMiddleware.slow_requests!
end
after do
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
end
it 'shows "Cancel" button on uploading', :js do
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
......
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