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